【问题标题】:How to remove/uninstall an old version of a gem删除/卸载旧版本的 ruby​​ gem
【发布时间】:2024-05-04 13:25:02
【问题描述】:

我在运行 rails 服务器时更新了一个 gem,现在我的 gemset 中安装了 2 个版本的 gem。

我使用bundle update bootstrap-sass 更新,现在拥有2.0.12.0.2

服务器似乎在提供 2.0.1 版本,所以我认为它应该在更新时删除了 2.0.1 版本,而不是因为当时正在使用 gem。

谁能告诉我如何正确更新它以便服务器使用 2.0.2 而不是 2.0.1 或如何删除 2.0.1 版本的 gem。

【问题讨论】:

  • 您可以通过在 Gemfile 中声明类似 <gemname>'2.0.2' 的内容来明确告诉您的程序使用 2.0.2 版本。

标签: ruby-on-rails-3 gem rvm twitter-bootstrap bundler


【解决方案1】:

您可以使用以下命令删除特定版本的 gem:

gem uninstall gem_name --version version

要删除bootstrap-sass 2.0.1,那将是:

gem uninstall bootstrap-sass --version 2.0.1

或者,您可以按照其他人的建议告诉 bundler 使用特定版本。在您的 Gemfile 中:

gem 'bootstrap-sass', '2.0.2' 将仅使用版本 2.0.2

gem 'bootstrap-sass', '~> 2.0.2' 将使用高于 2.0.2 但低于 2.1 的最高版本。

More Information on Specifying Versions in a Gemfile

【讨论】:

  • 谢谢保罗。我选择使用您的脚本卸载 2.0.1 版本,它现在根据需要使用 2.0.2。我以前从未更新过 gem,你认为这是因为我更新时网络服务器正在运行造成的吗?
【解决方案2】:

你需要的方法:

# remove version 2.0.1 and 2.0.2 only
gem uninstall bootstrap-sass --version 2.0.1
gem uninstall bootstrap-sass --version 2.0.2

其他从 PC 中移除宝石的方法:

# remove all old versions of the gem
gem cleanup bootstrap-sass

# choose which ones you want to remove
gem uninstall bootstrap-sass

【讨论】: