如何在命令行上将gem更新为特定版本



我使用的是Rails 4.2.3。我想在命令行上更新一个特定的gem(rspec(,但我似乎无法让它工作。

$ 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'

使用bin/bundle命令行工具将gem更新到特定版本的正确方法是什么?

将gem的版本更新为特定版本的正确方法是在Gemfile中指定所需的版本,然后运行bundle install

您可以将捆绑包锁定到特定版本,如以下所示:

gem "rspec-rails", "3.9"

或者,你可以这样做来获取3.9版本和所有发布的补丁:

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

至于命令行失败的原因,没有-version选项。而且,因为您使用了单点划线(-(,所以单词version被解释为一个字母选项列表,-v-e-r等。由于没有-v-e选项,bundler忽略了它们,并尝试使用-r选项,这是--retry的短选项。但是,该选项需要一个参数。

您可以通过以下命令了解更多可用选项:

bundle update --help

如果我们想更新这样的版本

从升级版

gem 'ar-octopus'

到较低版本

gem 'ar-octopus', '0.9.2'

然后运行命令

bundle update 'ar-octopus'

Gemfile.lock文件显示了gem 的向下版本

要从命令行只执行,我找到的一种方法是删除gem,然后在特定版本重新添加它:

# 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

注意:这不会在所有情况下都完美,但对我来说已经足够了。

最新更新