How do I update a gem to a specific version on the command line?

Viewed 3459

I'm using Rails 4.2.3. I would like to update a specific gem (rspec) on the command line, however I can't seem to get it to work.

$ bundle update rspec-rails -version 3.9
No value provided for option '--retry'
$ bundle update rspec-rails -version 3.9 --retry==1
No value provided for option '--retry'
$ bundle update rspec-rails -version 3.9 --retry=1
No value provided for option '--retry'

What's the right way to update a gem to a specific version using the bin/bundle command line tool?

1 Answers

The correct way to update the version of a gem to a specific version is to specify the version you want in your Gemfile, then run bundle install.

You can lock your bundle to a specific version, like this:

gem "rspec-rails", "3.9"

Or, you can do this to grab version 3.9 and all patches as they are released:

gem "rspec-rails", "~>3.9"

As for why your command line was failing, there is no -version option. And, because you used a single dash (-) the word version was interpreted as a list of one letter options, -v, -e, -r, etc. Since there are no -v or -e options, bundler ignored them and tried to use the -r option which is the short option for --retry. But, that option requires a parameter.

You can learn more about what options are available with this command:

bundle update --help
Related