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

3

11

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?

Teddi answered 24/3, 2022 at 15:22 Comment(0)
L
10

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
Lucrece answered 26/3, 2022 at 19:0 Comment(0)
C
2

If we want to update the version like

from up version

gem 'ar-octopus'

to lower version

gem 'ar-octopus', '0.9.2'

Then run command

bundle update 'ar-octopus'

Gemfile.lock file shows the down version of the gem

Carlos answered 26/9, 2022 at 13:39 Comment(0)
L
1

To do it only from the command line, one way I found is to remove the gem and then re-add it at a specific version:

# first remove from the Gemfile and Gemfile.lock
bundle remove cocoapods

# now re-add it at the specific version we want
bundle add cocoapods --version 1.12.0

NB: this won't work perfectly in all situations but is good enough for me, for now.

Limeade answered 14/3, 2023 at 8:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.