I want to install awesome_print in my dockerized ruby application. Running
docker-compose run application_name gem install awesome_print
says "Successfully installed awesome_print-1.8.0," however, it does not appear in my Gemfile even after running
docker-compose run application_name bundle install
How can I install awesome_print in my dockerized application?
The RubyGems gem command is actually a much older package manager that predates bundler.
Running gem install foo just installs the gem to your local repository (a folder somewhere). It does not add the gem to your Gemfile and it does not perform the dependency tree resolution that Bundler does to ensure that your gems are actually compatible.
Bundler is built on top of gem. To install gems with bundler (which is what you pretty much always want to do) you add the gem to your Gemfile and run bundle install.
gem 'awesome_print', '~> 1.8'
Bundler also has a bundle add command which will add a gem to the Gemfile and install your bundle, for example:
bundle add awesome_print --version "~> 1.8"
Related
I am trying to upgrade a gem (hydra-derivatives) to version 3.3.2 to see if it solves a bug we are having.
hydra-derivatives is not a Gemfile gem; it's bundled as a dependency of another gem, called hydra-works.
What I've Tried
bundle update --conservative
hydra-derivatives but that only upgraded hydra-derivatives to
3.2.2 (& we want 3.3.2) and its dependency mini_magick from 4.5.1 to 4.8.0
adding gem 'hydra-derivatives', '~> 3.3.2' but that gave me:
You have requested:
hydra-derivatives ~> 3.3.2
The bundle currently has hydra-derivatives locked at 3.2.1.
Try running `bundle update hydra-derivatives`
If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`
I don't want to run bundle update hydra-derivatives because I don't want it to update a bunch of unnecessary gems and cause problems, hence why I read about --conservative
a. I ran this anyway to test it, and it upgraded target gem to only 3.2.2 and 15 gems in total!
hydra-derivatives is not a Gemfile gem; it's bundled as a dependency of another gem, called hydra-works.
You can still add this as an explicit dependency in your Gemfile:
# only restrict the version if you know of an incompatibility
gem 'hydra-derivatives' , '~> 3.3'
then run
bundle update hydra-derivatives --conservative
or
bundle update hydra-works --conservative
Remove the hydra-works gem from your Gemfile.
Either remove the gem and its dependencies by hand from the installed gem location or if you have the application in its own Ruby environment using rbenv or rvm run bundle clean --force.
Beware bundle clean --force will remove all of the gems in the Ruby version other than those specified in your Gemfile. If you have other applications that use the same version of Ruby you'll have to reinstall the gems for that application if they are different than what you are using in this application.
Add this to your Gemfile
gem 'hydra-derivatives', '~> 3.3.2'
gem 'hydra-works'
And run bundle install
You should see the correct dependency version now in your Gemfile.lock
I am trying to rails server from a cloned repo, I have updated ruby, and rails, followed the rvm process, updated all my gem files, and when I go to serve I receive the message
Could not find globalid-0.3.7 in any of the sources Run bundle
install to install missing gems.
So I do bundle install, then get the error
An error occurred while installing pg (0.20.0), and Bundler cannot
continue. Make sure that gem install pg -v '0.20.0' succeeds before
bundling.
Try to insall that and then get
ERROR: Could not find a valid gem 'globalid-0.3.7' (>= 0) in any
repository ERROR: Possible alternatives: globalid, globalize3
I have googled everything and asked many.
globalid is a dependency of the Rails core gem ActiveJob so it is a required gem to have in your Gemfile.lock. See if it is listed in your Gemfile.lock file. If not you could add it to the top of your gemfile including the version
# gemfile
gem 'globalid', '0.3.7'
Then bundle install. If it works, then you can delete it from your gemfile since it should load automatically when Rails loads (since it is a dependency of Rails' ActiveJob). I've run into a similar issue with another gem and this process worked for me.
It could be a version error. Try using gem 'globalid', '~> 0.4.0' in your gemfile and bundling.
when I tried to start Server with command rails -s that throw an error:
Could not find gem 'therubyracer x86-mingw32' in any of the gem sources listed i
n your Gemfile.
Run bundle install to install missing gems.
I also try with
gem install
gem update ...
but no effect
my gem file:
gem 'therubyracer', group: :production
I don't know why that can not run! but run with another project is OK.
how can I resolve this?
You can run bundle install --without production to skip that gem being installed for development.
I am in an older Rails project that has a Gemfile. I tried to add a gem to the Gemfile and bundle install but got an error:
Bundler could not find compatible versions for gem "bundler":
In Gemfile:
rails (= 3.0.0) ruby depends on
bundler (~> 1.0.0) ruby
Current Bundler version:
bundler (1.1.5)
This Gemfile requires a different version of Bundler.
The version of Rails it's using requires bundler ~>1.0.0 but I have 1.1.5 installed and am using it for my other projects. Usually I would use bundle exec ... but since this is bundler we are talking about, it's a little more complicated than that. How can I add a gem to my Gemfile and run bundle install while using the version of bundler that it requires?
First you need to install the appropriate version of bundler:
% gem install bundler -v '~> 1.0.0'
Successfully installed bundler-1.0.22
Then force rubygems to use the version you want (see this post):
% bundle _1.0.22_ install
This is what I had to do to get it to work to install with a previous version (2.2.11) of bundler:
gem install bundler:2.2.11
bundle _2.2.11_ install
The error message In Gemfile: bundler (~> 1.16) is a bit inaccurate, since the version number requirement can come from other places, such as the .gemspec file, which was the case for me:
spec.add_development_dependency "bundler", "~> 1.16"
Removing the version number from the .gemspec file solved the issue for me:
spec.add_development_dependency "bundler"
I had the same issue on macOS Mojave. I installed the different version of the bundler gem and uninstall the current version.
gem install bundler -i '2.0.1'
gem uninstall bundler
Then gives me the option to choose the version to uninstall and I choose the one which is creating the problem.
If you use rvm to manage your ruby versions consider using gemsets for projects. This way you can install the specific version of bundler needed without having to specify the version each time.
You can confirm your gemset is loaded by running rvm info in your project directory.
Now you can install the version of bundler you'd like via gem install bundler -v '~> <VERSION>'. The next time you need to use bundler just run bundle.
I need to use addressable 2.2.4 gem, but I have 2.2.5 version (because of an issue discussed here: https://github.com/sporkmonger/addressable/pull/33). I tried:
source 'http://rubygems.org'
source 'http://gems.github.com'
gem "addresable", "2.2.4"
bundle install
and get Could not find gem 'adressable (= 2.2.4, runtime)' in any of the gem sources listed in your Gemfile.
If I install/uninstall gem manually by
sudo gem install addressable -v 2.2.4
sudo gem uninstall addressable -v 2.2.5
I get the same error.
So, how can I force 2.2.4 version for my app?
You've misspelled "addressable" in your gem line.
Your bundle might be locked at 2.2.5 — try running bundle update. It's counter-intuitive, but it'll rebuild your Gemfile.lock with the specified version.
You don't need gems.github.com as a source anymore — they quit building it and recommend rubygems.org.