导轨捆绑清洁
更新捆绑包后,您将拥有一些可能已过时的 gem - 因为已安装该 gem 的较新版本。 bundle
可执行文件(即 bundle clean
)下没有这样的命令。如何摆脱这些过时的宝石?
这是减少我的 Rails 应用程序中的 slug 大小的尝试。
After updating a bundle, you will have some gems that may be obsolete -- since a newer version of that gem has been installed. There is no such command under the bundle
executable i.e. bundle clean
. How does one get rid of these obsolete gems?
This is an attempt to reduce slug size in my rails app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您使用的是 Bundler 1.1 或更高版本,您可以使用
bundle clean
,就像您想象的那样。如果您使用bundle install --path
(Bundler 管理您使用 --path 指定的位置,因此负责删除过时的 gem),但如果您使用 Bundler 来安装,这是多余的将 gem 作为系统 gem,然后bundle clean --force
将删除 Gemfile 不需要的任何系统 gem。非常明显的警告:如果您有其他应用程序依赖于 Gemfile 中不存在的系统 gem,请不要这样做!Pat Shaughnessy 对
bundle clean
以及捆绑器 1.1 中的其他新增内容。If you are using Bundler 1.1 or later you can use
bundle clean
, just as you imagined you could. This is redundant if you're usingbundle install --path
(Bundler manages the location you specified with --path, so takes responsibility for removing outdated gems), but if you've used Bundler to install the gems as system gems thenbundle clean --force
will delete any system gems not required by your Gemfile. Blindingly obvious caveat: don't do this if you have other apps that rely on system gems that aren't in your Gemfile!Pat Shaughnessy has a good description of
bundle clean
and other new additions in bundler 1.1.如果您使用 RVM,则可以对当前 gemset 使用 rvm gemsetempty - 此命令将删除安装到当前 gemset 的所有 gem(gemset 本身将保留在原位)。然后运行
bundle install
以安装实际版本的gems。另外,请确保在rvm gemsetempty
期间不要删除诸如 rake、bundler 等常规 gem(如果是这种情况,请先通过gem install
手动安装它们)到捆绑安装
)。If you're using RVM you may use
rvm gemset empty
for the current gemset - this command will remove all gems installed to the current gemset (gemset itself will stay in place). Then runbundle install
in order to install actual versions of gems. Also be sure that you do not delete such general gems as rake, bundler and so on duringrvm gemset empty
(if it is the case then install them manually viagem install
prior tobundle install
).如果您使用 RVM,您可以将 gem 安装到 gemsets 中。这样,当您想要执行完全清理时,您可以简单地删除宝石集,从而删除其中安装的所有宝石。您的另一个选择是简单地卸载未使用的 gem,然后重新运行
bundle install
命令。由于bundler是一个针对每个项目的gem版本控制工具,它不提供
bundle clean
命令。这样做意味着也可能删除与其他项目相关的宝石,这是不可取的。这意味着捆绑器可能不是用来管理 gem 目录的错误工具。我个人的建议是使用 RVM gemsets 将您的 gems 沙箱到某些项目或 ruby 版本中。If you are using RVM you can install your gems into gemsets. That way when you want to perform a full cleanup you can simply remove the gemset, which in turn removes all the gems installed in it. Your other option is to simply uninstall your unused gems and re-run your
bundle install
command.Since bundler is meant to be a project-per-project gem versioning tool it does not provide a
bundle clean
command. Doing so would mean the possibility of removing gems associated with other projects as well, which would not be desirable. That means that bundler is probably the wrong tool to use to manage your gem directory. My personal recommendation would be to use RVM gemsets to sandbox your gems in certain projects or ruby versions.老实说,我在捆绑器循环依赖方面遇到了问题,最好的方法是 rm -rf .bundle 。省去麻烦,只需使用锤子即可。
Honestly, I had problems with bundler circular dependencies and the best way to go is
rm -rf .bundle
. Save yourselves the headache and just use the hammer.我假设您将 gems 安装到
vendor/bundle
中?如果是这样,为什么不删除所有 gem 并执行干净的捆绑安装
?I assume you install gems into
vendor/bundle
? If so, why not just delete all the gems and do a cleanbundle install
?在寻找同一问题的答案时,我遇到了gem_unused。
您可能还想阅读这篇文章:http:// chill.manilla.com/2012/12/31/clean-up-your-dirty-gemsets/
源代码可在 GitHub 上获取:https://github.com/apolzon/gem_unused
When searching for an answer to the very same question I came across gem_unused.
You also might wanna read this article: http://chill.manilla.com/2012/12/31/clean-up-your-dirty-gemsets/
The source code is available on GitHub: https://github.com/apolzon/gem_unused
只需从 Gemfile 中删除过时的 gem。如果您谈论的是 Heroku(您没有提及),那么每个新版本都会编译 slug,仅使用该文件的当前内容。
Just remove the obsolete gems from your Gemfile. If you're talking about Heroku (you didn't mention that) then the slug is compiled each new release, just using the current contents of that file.
只需执行即可清理过时的宝石并删除捆绑后的打印警告。
Just execute, to clean gems obsolete and remove print warningns after bundle.