Ruby-on-rails 卸载 rails 和 gems,出现错误“无法卸载,检查 'gem list -d ...'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4007074/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:27:56  来源:igfitidea点击:

Uninstalling rails and gems, getting error "cannot uninstall, check 'gem list -d ...'

ruby-on-railsrubygemsosx-snow-leoparduninstallrvm

提问by GiH

I'm going to start with the usual noob line, "I'm new to rails". Oh, and I'm running Mac OSX 10.6.4

我将从通常的菜鸟行开始,“我是 Rails 新手”。哦,我运行的是 Mac OSX 10.6.4

I've been following a bunch of guides to get set up, specifically these two hereand here. The guides are great, the reason I'm using the second one is because of RVM and the reason I'm using the first is for MYSQL.

我一直在遵循一堆指南进行设置,特别是这两个herehere。指南很棒,我使用第二个的原因是因为 RVM,而我使用第一个的原因是针对 MYSQL。

Anyway, when I started, I wasn't following the directions completely and so after I installed RVM, for some reason I installed rails with sudo gem install rails -v 2.3.8because thats the version I need. So... I realized I was using the system ruby, and wasn't taking advantage of RVM. What I did now was install Ruby 1.9.2 so I can install rails 3 and test it out, and I also installed 1.8.7 and rails 2.3.8 so I can use it for what I need it.

无论如何,当我开始时,我并没有完全按照说明进行操作,因此在安装 RVM 之后,出于某种原因,我安装了 rails,sudo gem install rails -v 2.3.8因为那是我需要的版本。所以......我意识到我正在使用系统ruby,并没有利用RVM。我现在所做的是安装 Ruby 1.9.2,这样我就可以安装 rails 3 并对其进行测试,我还安装了 1.8.7 和 rails 2.3.8,这样我就可以将它用于我需要的地方。

Now, I'm trying to uninstall the gems from the system Ruby, but whenever I try to I'm getting this error:

现在,我正在尝试从系统 Ruby 中卸载 gem,但是每当我尝试时,都会收到此错误:

ERROR: While executing gem ... (Gem::InstallError)
cannot uninstall, check 'gem list -d whatever gem I try to uninstall'

错误:执行 gem 时 ... (Gem::InstallError)
无法卸载,请检查“gem list -d 我尝试卸载任何 gem

Any ideas on how to remove rails and all these gems? I just want to start from scratch with RVM.

关于如何移除导轨和所有这些宝石的任何想法?我只想从头开始使用 RVM。



UPDATE:

更新:

By running the command gem list -d railsI've located the gems in /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/18. Should I delete them manually?

通过运行命令,gem list -d rails我在 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/18 中找到了 gem。我应该手动删除它们吗?

回答by GiH

SOLUTION!! I still don't understand why this happened, I'd love if someone could explain. Why was the path non-existant? What caused this error?

解决方案!我仍然不明白为什么会发生这种情况,如果有人能解释一下,我很乐意。为什么路径不存在?是什么导致了这个错误?

Also, I want to mention that the solution I linked to has a comment saying that the question is a duplicate. However, the original has a different solution and did not help me (though its the basis to finding this answer). Simply deleting the gems manually in finder would not remove them from the gem list.

另外,我想提一下,我链接到的解决方案有一条评论说这个问题是重复的。然而,原版有一个不同的解决方案,并没有帮助我(尽管它是找到这个答案的基础)。简单地在 finder 中手动删除宝石不会将它们从宝石列表中删除。

Without further ado- it turns out that when trying to uninstall the gem, it can't locate its path (I think the problem is because of installing with sudo, but I might be wrong). What you need to do is (you have to do this one by one for each gem, or at least I had to):

事不宜迟- 事实证明,当尝试卸载 gem 时,它无法找到它的路径(我认为问题是因为使用 sudo 安装,但我可能错了)。您需要做的是(您必须为每个宝石一个一个地执行此操作,或者至少我必须这样做):

  1. gem list -d 'name of gem'and note the "Installed at:" location (in my case, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8)
  2. sudo gem uninstall 'name of gem' -i 'the path noted above'(ex. in my case, sudo gem uninstall rails -i /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
  3. Some gems still might not uninstall returning a permissions error. If this is the case, what you need to do is create a folder /bin, in the path above. (in my case, mkdir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/bin
  4. Continue uninstalling as in step 2, still using the original path (/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8).
  1. gem list -d 'name of gem'并注意“安装在:”位置(在我的情况下,/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8)
  2. sudo gem uninstall 'name of gem' -i 'the path noted above'(例如,就我而言, sudo gem uninstall rails -i /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
  3. 某些 gem 可能仍无法卸载并返回权限错误。如果是这种情况,您需要做的是在上面的路径中创建一个文件夹 /bin。(就我而言,mkdir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/bin
  4. 继续按照步骤 2 进行卸载,仍然使用原始路径 (/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8)。

Now all uninstalls should work!

现在所有卸载都应该可以工作!

回答by calas

Two things you should note when using rvm:

使用 rvm 时应注意的两件事:

  1. You should NEVERuse sudoto install gems, just do a gem install xxx

  2. You can not uninstall gems installed in the globalgemset from within another gemset. You should switch to the global gemset and uninstall from there:

  1. 你应该永远不会使用sudo安装宝石,只是做了gem install xxx

  2. 您不能从另一个 gemset 中卸载安装在全局gemset中的 gem 。您应该切换到全局 gemset 并从那里卸载:


 rvm gemset use global
 gem uninstall xxx

回答by jacobsimeon

execute this either in irb or in a script proper:

在 irb 或适当的脚本中执行此操作:

`gem list --no-versions`.split("\n").each do |gem|
  `gem list -d #{gem}`.gsub(/Installed at(.*):.*/).each do |dir|
    dir = dir.gsub(/Installed at(.*): /,'').gsub("\n", '')
    system "gem uninstall #{gem} -aIx -i #{dir}"
  end  
end

回答by Luan D

try this way :

试试这种方式:

sudo apt purge rails

回答by Waheed

A more generic answer to delete all gems for older versions of gem 1.8.

删除旧版本 gem 1.8 的所有 gem 的更通用答案。

gem list --no-versions | xargs sudo gem uninstall -aIx

宝石列表 --no-versions | xargs sudo gem 卸载 -aIx

回答by atw

I was using RVM to manage my gemsets and had not selected the gemset. I wasn't that I had selected the wrong gemset, it was that I hadn't selected the gemset at all. A lovely way to spend the bulk of an hour of my first morning back after my summer holidays!

我使用 RVM 来管理我的 gemset 并且没有选择 gemset。我不是我选错了宝石,而是我根本没有选择宝石。在我暑假后的第一个早晨度过大部分时间的好方法!

回答by Justin Soliz

ok i see....

好的我明白了....

at this point, if you're in the terminal, it shouldn't take but a few minutes to reinstall the whole shebang

此时,如果您在终端中,重新安装整个 shebang 应该只需要几分钟

I suspect you might not be in the correct rvm name that has the gems you're trying to install so thats why i'd suggest reinstalling rubygems and building you're core gems from the beginning in your Globalrvm gemset name.

我怀疑您可能没有使用正确的 rvm 名称来安装您要安装的 gem,所以这就是为什么我建议重新安装 ruby​​gems 并从一开始就以Globalrvm gemset 名称构建您的核心 gem 。