Ruby-on-rails 如何使用捆绑器强制更新 gem?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7897113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to force the update of a gem with bundler?
提问by Dominic Goulet
I have a private git server hosting a gem we developed. The gem got some commits, but the version did not actually change.
我有一个私人 git 服务器托管我们开发的 gem。gem 得到了一些提交,但版本实际上并没有改变。
How can I force bundler to update my gem even if the version hasn't changed?
即使版本没有改变,我如何强制捆绑器更新我的 gem?
I tried "bundler update mygemname" but it did not update anything.
我试过“bundler update mygemname”,但它没有更新任何东西。
Thanks
谢谢
采纳答案by Tilo
that will not work - there is no "force" option - you will have to modify your .gemspec file and increase the version number, then do gem build ..., and bundle install
这是行不通的——没有“强制”选项——你必须修改你的 .gemspec 文件并增加版本号,然后做gem build ...,然后bundle install
It is critical for bundler to be able to read the version number from your gem, which was introduced in the .gemspecfile. It's confusing not only to bundler or gem update, but also confusing to people if you forget to update the version number in the .gemspec file. They would end up having gem-files lying around, and not be able to tell which versions they are, e.g. which one is newer? (of course you could use md5-sum, but that's beside the point here).
bundler 能够从.gemspec文件中引入的 gem 中读取版本号是至关重要的。gem update如果您忘记更新 .gemspec 文件中的版本号,这不仅会使bundler 或感到困惑,而且还会使人们感到困惑。他们最终会得到一些 gem 文件,并且无法分辨它们是哪个版本,例如哪个版本较新?(当然你可以使用 md5-sum,但这不是重点)。
The best thing to do is to correct the mistake in the .gemspec file, and re-release the gem.
最好的办法是纠正 .gemspec 文件中的错误,然后重新发布 gem。
Check the bundler source code for available options:
检查捆绑器源代码以获取可用选项:
e.g.: bundler-1.0.15/lib/bundler/cli.rb
例如: bundler-1.0.15/lib/bundler/cli.rb
(search for desc "install")
(搜索desc "install")
回答by sbeam
you can also put the git hashref right in the Gemfile with the :refoption
您还可以使用:ref选项将 git hashref 放在 Gemfile 中
gem 'foo', :git => 'git://github.com/foobar/foo.git', :branch => '0.9-beta', :ref => '9af382ed'
especially useful if you don't have control over said gem, and keeps bundler from giving you a newer version in case there are breaking changes.
如果您无法控制所说的 gem,则特别有用,并防止捆绑程序为您提供更新版本,以防发生重大更改。
回答by jdl
First of all, don't do that. If you change your gem, you should be updating its version number. Otherwise, it's just confusing.
首先,不要这样做。如果你改变了你的 gem,你应该更新它的版本号。否则,它只是令人困惑。
If you really want to do this, however, you can apply the giant hammer of removing your gem first.
但是,如果您真的想这样做,您可以先使用巨锤去除宝石。
$ gem uninstall foo
$ bundle update
回答by Nowhere man
From version 1.11 bundle installjust has a --forceoption that will redownload every gem even if they are already installed.
从 1.11 版开始,bundle install只有一个--force选项可以重新下载每个 gem,即使它们已经安装。
回答by Eric Boehs
This doesn't answer the exact question above, but I was searching for "How to force update a gem in bundler" on Google and this came up.
这并没有回答上面的确切问题,但我在谷歌上搜索“如何强制更新捆绑器中的 gem”,结果出现了。
I'm not trying to force update a gem to rubygems.org but rather I'm trying to reinstall a gem that's installed to a bundle path on my local system. Specifically I'm trying reinstall a gem with a native extension (nokogiri).
我不是要强制将 gem 更新到 rubygems.org,而是尝试重新安装安装到本地系统上的包路径的 gem。具体来说,我正在尝试重新安装带有本机扩展名 (nokogiri) 的 gem。
How I removed it from my project is as follows; assuming your --pathis vendor/bundleand you're in the project's root, run:
我如何从我的项目中删除它如下;假设您--path是vendor/bundle并且您在项目的根目录中,请运行:
find vendor/bundle/ruby/2.0.0 -name "*nokogiri*" -depth 2
Verify these files/directories are specific to nokogiri and then remove them with:
验证这些文件/目录特定于 nokogiri,然后使用以下命令删除它们:
find vendor/bundle/ruby/2.0.0 -name "*nokogiri*" -depth 2 | xargs rm -rf
Now you can run your bundle install command as usual:
现在你可以像往常一样运行你的 bundle install 命令:
bundle install --path vendor/bundle
Note:You'll of course need to change 2.0.0above to your ruby version. ls vendor/bundle/rubyto see which version bundler has installed gems for.
注意:您当然需要将2.0.0上面更改为您的 ruby 版本。ls vendor/bundle/ruby查看捆绑程序为哪个版本安装了 gems。

