ruby 如何使用 bundler 重新安装 gem
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12188833/
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 reinstall a gem using bundler
提问by waldyr.ar
I did a bundle showand get the complete path to a gem directory.
我做了一个bundle show并获得了 gem 目录的完整路径。
Unfortunately, I removed the directory using rm -r gem_path. Then my rails app isn't working anymore. If I try start server or start rails console it outputs the following error:
不幸的是,我使用rm -r gem_path. 然后我的 rails 应用程序不再工作了。如果我尝试启动服务器或启动 rails 控制台,它会输出以下错误:
<class:Application>: uninitialized constantMyAPP::Application::Gem(NameError)
<class:Application>: 未初始化的常量MyAPP::Application::Gem(NameError)
What should I do to have it back?
我该怎么做才能取回它?
I tried bundle installor bundle updatein hope of forcing the bundle to search the gem and install it back, but didn't work.
我尝试bundle install或bundle update希望强制捆绑包搜索 gem 并将其安装回去,但没有奏效。
I also tried delete the Gemfile.lockand run bundle install. Nothing changed, same error.
我也尝试删除Gemfile.lock并运行bundle install. 什么都没有改变,同样的错误。
The gem in question is Act as taggable on.
有问题的 gem 是Act as taggable on。
采纳答案by waldyr.ar
First I did a gem q --L, the shortcut for gem query --local. It outputs me the all the local gems installed.
首先我做了一个gem q --L,快捷方式gem query --local。它向我输出安装的所有本地 gem。
actionmailer (3.2.8, 3.2.6, 3.2.1, 3.1.0)
actionpack (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activemodel (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activerecord (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activeresource (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activesupport (3.2.8, 3.2.6, 3.2.1, 3.1.0)
acts-as-taggable-on (2.3.3)
...
And then, following DVG advice, I uninstalled the gem using its correct name gem uninstall acts-as-taggable-onand ran bundle install. After that I was able to rails cor rails sagain without any problem.
然后,按照 DVG 的建议,我使用正确的名称卸载了 gemgem uninstall acts-as-taggable-on并运行bundle install. 在那之后,我能够rails c或rails s再次没有任何问题。
回答by werkshy
If using rbenv, this will let you completely uninstall and re-install a gem such as rmagick:
如果使用 rbenv,这将让您完全卸载并重新安装 gem,例如 rmagick:
First: Try a simple uninstall/reinstall
第一:尝试简单的卸载/重新安装
gem uninstall rmagick
bundle install
If that doesn't work, you can remove all trace of the installed gem. Find your gem installation location:
如果这不起作用,您可以删除已安装 gem 的所有痕迹。找到您的 gem 安装位置:
bundle show rmagick
BUNDLE_DIR=$(dirname $(dirname $(bundle show rmagick)))
echo $BUNDLE_DIR
Your gem installation prefix will either be the default e.g. ~/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0or something you set e.g. .vendor
你的 gem 安装前缀要么是默认的,~/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0要么是你设置的,例如.vendor
Clear out the gem directory:
清除 gem 目录:
rm -rf $BUNDLE_DIR/gems/rmagick-*
Clear out the compiled gem cache:
清除已编译的 gem 缓存:
rm $BUNDLE_DIR/cache/rmagick*.gem
Also clear out bundler's spec cache:
还要清除 bundler 的规范缓存:
rm $BUNDLE_DIR/specifications/rmagick*gemspec
Then you can re-install:
然后你可以重新安装:
bundle install
回答by Calin
You can always use:
您可以随时使用:
gem pristine acts-as-taggable-on
gem pristine acts-as-taggable-on
pristine - Restores installed gems to pristine condition from files located in the gem cache
原始 - 从位于 gem 缓存中的文件中将安装的 gem 恢复到原始状态
If you just want to restore the gem for the current project you should run:
如果您只想恢复当前项目的 gem,您应该运行:
bundle exec gem pristine acts-as-taggable-on
bundle exec gem pristine acts-as-taggable-on
回答by Sazzad
From project directory in terminal
从终端中的项目目录
gem uninstall gem_name
回答by JosephL
If using RVMwith gems in ~/.rvm/, this works if bundleis not re-installing a gem.
如果在 中使用带有 gems 的RVM,~/.rvm/如果bundle不重新安装 gem ,这会起作用。
First, delete the gem source:
首先,删除gem源:
bundle show $GEM
rm -rf $PATH_TO_GEM
Clear out the compiled gem cache:
清除已编译的 gem 缓存:
rm -rf ~/.rvm/gems/ruby-$RUBYVERSION[@$GEMSET]/cache/$GEM.gem
Also clear out bundler's spec cache:
还要清除 bundler 的规范缓存:
rm -rf ~/.rvm/gems/ruby-$RUBYVERSION[@$GEMSET]/specifications/$GEM*gemspec
Then you can re-install:
然后你可以重新安装:
bundle install
回答by ioquatix
If you've installed into ./bundle/vendoror similar, you need to remove the gem first but explicitly specify the GEM_HOME, e.g.
如果你已经安装到./bundle/vendor或类似的,你需要先删除 gem 但明确指定 GEM_HOME,例如
GEM_HOME=./vendor/bundle/ruby/2.3.0/ gem uninstall rmagick
This is by far the simplest way to uninstall gems installed using bundler into a vendor directory. Ideally, there would be a command bundle uninstallor bundle reinstall, etc.
这是迄今为止将使用 bundler 安装的 gem 卸载到供应商目录中的最简单方法。理想情况下,会有一个命令bundle uninstallorbundle reinstall等。
If your goal is to simply reinstall, the following command will help:
如果您的目标是简单地重新安装,以下命令将有所帮助:
GEM_HOME=./vendor/bundle/ruby/2.3.0/ gem uninstall rmagick && sudo -u http bundle install
If you're like me and have several web-applications under a directory (e.g. /srv/http), the following does it in all directories:
如果您像我一样并且在一个目录下有多个 Web 应用程序(例如/srv/http),则在所有目录中执行以下操作:
cd /srv/http
for d in ./*/ ; do (cd "$d" && sudo -u http GEM_HOME=./vendor/bundle/ruby/2.4.0/ gem uninstall --force rmagick && sudo -u http bundle install); done
回答by Magne
bundle exec gem uninstall <gem_name>- uninstalls gem from the bundle (the <app_root>/vendor/bundle/ruby/2.3.0/gems/path). This is equivalent to the answer @ioquatix gave, but is the slightly more convenient solution that he was looking for.
bundle exec gem uninstall <gem_name>- 从包(<app_root>/vendor/bundle/ruby/2.3.0/gems/路径)中卸载 gem 。这相当于@ioquatix 给出的答案,但他正在寻找更方便的解决方案。
gem uninstall <gem_name>- uninstalls gem only from the global gemset in the system
gem uninstall <gem_name>- 仅从系统中的全局 gemset 中卸载 gem
回答by Matthias Winkelmann
If you're trying to reinstall rake, gem pristine rakewill fail with Skipped rake-10.X.X, it is a default gemand bundle won't install it either, because it can't uninstall it.
如果您尝试重新安装 rake,gem pristine rake将会失败Skipped rake-10.X.X, it is a default gem并且 bundle 也不会安装它,因为它无法卸载它。
If you're using rvm, it seems the easiest was is simply to do a rvm reinstall 2.x.x. At least for me, rvm repair allalso didn't help.
如果您使用的是 rvm,似乎最简单的方法就是执行rvm reinstall 2.x.x. 至少对我来说,rvm repair all也没有帮助。
The same probably goes for all other default gems. I'll just list them here so that the desperate googlers find some help:
所有其他默认 gem 可能也是如此。我会在这里列出它们,以便绝望的谷歌员工找到一些帮助:
- bigdecimal
- drip
- io-console
- json
- minitest
- psych
- rake
- rbtree
- rdoc
- test-unit
- 大十进制
- 滴
- io控制台
- json
- 小测试
- 心理
- 耙
- 树
- 文件
- 测试单元

