我正在使用 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
注意:这并不是在所有情况下都能完美工作,但目前对我来说已经足够了。