I did a bundle show
and get the complete path to a gem directory.
我做了一个捆绑展示,得到了通往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)<类:应用> :uninitialized constant MyAPP::::应用:::Gem (NameError)
What should I do to have it back?
我该怎么做才能找回它?
I tried bundle install
or bundle update
in hope of forcing the bundle to search the gem and install it back, but didn't work.
我尝试了bundle install或bundle update,希望迫使bundle搜索gem并将其安装回来,但没有成功。
I also tried delete the Gemfile.lock
and run bundle install
. Nothing changed, same error.
我还尝试删除Gemfile。锁定并运行bundle安装。没有什么改变,同样的错误。
The gem in question is Act as taggable on.
所讨论的宝石具有标记性。
8 个解决方案
#1
39
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.0
or something you set e.g. .vendor
你的gem安装前缀可能是默认的,例如:~/.rbenv/版本/2.2.2/lib/ruby/gems/2.2.0或者你设置的一些东西。
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
#2
35
You can always use:
你可以使用:
gem pristine acts-as-taggable-on
宝石原始acts-as-taggable-on
pristine - Restores installed gems to pristine condition from files located in the gem cache
原始-从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 -as-taggable-on
#3
12
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查询的快捷方式——local。它输出所有本地的宝石。
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-on
and ran bundle install
. After that I was able to rails c
or rails s
again without any problem.
然后,根据DVG建议,我使用正确的名称gem卸载了gem—as- taggabon,并运行bundle install。在那之后,我就可以再次使用rails c或rails s了,没有任何问题。
#4
9
From project directory in terminal
从终端的项目目录
gem uninstall gem_name
#5
8
If using RVM with gems in ~/.rvm/
, this works if bundle
is not re-installing a gem.
如果在~/中使用RVM和gems。如果bundle不重新安装gem,则此操作有效。
First, delete the gem source:
首先,删除创业板来源:
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
#6
3
If you're trying to reinstall rake, gem pristine rake
will fail with Skipped rake-10.X.X, it is a default gem
and bundle won't install it either, because it can't uninstall it.
如果您试图重新安装rake, gem原始rake将会在跳过rake- 10.x时失败。它是一个默认的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 all
also didn't help.
如果您正在使用rvm,似乎最简单的方法就是执行rvm重新安装2.x.x。至少对我来说,rvm的修复也没有帮助。
The same probably goes for all other default gems. I'll just list them here so that the desperate googlers find some help:
对于所有其他默认的宝石,情况可能也是如此。我把它们列在这里,让那些绝望的谷歌人找到一些帮助:
- bigdecimal
- bigdecimal
- drip
- 滴
- io-console
- io-console
- json
- json
- minitest
- 小型试验
- psych
- 心理
- rake
- 耙
- rbtree
- rbtree
- rdoc
- 出来
- test-unit
- 试验装置
#7
3
If you've installed into ./bundle/vendor
or 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 uninstall
or bundle reinstall
, etc.
到目前为止,这是将使用bundler安装的gems卸载到供应商目录的最简单的方法。理想情况下,会有一个命令包卸载或重新安装,等等。
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
#8
2
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卸载
gem uninstall <gem_name>
- uninstalls gem only from the global gemset in the system
gem卸载
#1
39
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.0
or something you set e.g. .vendor
你的gem安装前缀可能是默认的,例如:~/.rbenv/版本/2.2.2/lib/ruby/gems/2.2.0或者你设置的一些东西。
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
#2
35
You can always use:
你可以使用:
gem pristine acts-as-taggable-on
宝石原始acts-as-taggable-on
pristine - Restores installed gems to pristine condition from files located in the gem cache
原始-从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 -as-taggable-on
#3
12
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查询的快捷方式——local。它输出所有本地的宝石。
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-on
and ran bundle install
. After that I was able to rails c
or rails s
again without any problem.
然后,根据DVG建议,我使用正确的名称gem卸载了gem—as- taggabon,并运行bundle install。在那之后,我就可以再次使用rails c或rails s了,没有任何问题。
#4
9
From project directory in terminal
从终端的项目目录
gem uninstall gem_name
#5
8
If using RVM with gems in ~/.rvm/
, this works if bundle
is not re-installing a gem.
如果在~/中使用RVM和gems。如果bundle不重新安装gem,则此操作有效。
First, delete the gem source:
首先,删除创业板来源:
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
#6
3
If you're trying to reinstall rake, gem pristine rake
will fail with Skipped rake-10.X.X, it is a default gem
and bundle won't install it either, because it can't uninstall it.
如果您试图重新安装rake, gem原始rake将会在跳过rake- 10.x时失败。它是一个默认的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 all
also didn't help.
如果您正在使用rvm,似乎最简单的方法就是执行rvm重新安装2.x.x。至少对我来说,rvm的修复也没有帮助。
The same probably goes for all other default gems. I'll just list them here so that the desperate googlers find some help:
对于所有其他默认的宝石,情况可能也是如此。我把它们列在这里,让那些绝望的谷歌人找到一些帮助:
- bigdecimal
- bigdecimal
- drip
- 滴
- io-console
- io-console
- json
- json
- minitest
- 小型试验
- psych
- 心理
- rake
- 耙
- rbtree
- rbtree
- rdoc
- 出来
- test-unit
- 试验装置
#7
3
If you've installed into ./bundle/vendor
or 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 uninstall
or bundle reinstall
, etc.
到目前为止,这是将使用bundler安装的gems卸载到供应商目录的最简单的方法。理想情况下,会有一个命令包卸载或重新安装,等等。
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
#8
2
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卸载
gem uninstall <gem_name>
- uninstalls gem only from the global gemset in the system
gem卸载