简体   繁体   English

摆脱 ruby 不会死的宝石

[英]getting rid of ruby gems that won't die

I've got a few ruby gems that won't go away.我有一些 ruby 宝石,它们不会 go 消失。

I think it has to do with when I installed them.我认为这与我安装它们的时间有关。 Occasionally I have forgotten to use "sudo" before doing a gem install, which results in a write error and from what I can gather puts a copy of the gem in my user directory instead of somewhere it can run.有时我忘记在安装 gem 之前使用“sudo”,这会导致写入错误,并且根据我收集到的信息,我会将 gem 的副本放在我的用户目录中,而不是它可以运行的地方。 But gem uninstall doesn't work.但是 gem uninstall 不起作用。 It continually shows up in 'gem list' but can't uninstall it from either gem uninstall, or sudo gem uninstall.它不断出现在“gem list”中,但无法通过 gem uninstall 或 sudo gem uninstall 将其卸载。 I tried directly deleting one gem after finding the path in my 'gem environment', but that still left the gem on the list.在我的“gem 环境”中找到路径后,我尝试直接删除一个 gem,但仍然将 gem 留在列表中。

Also is it possible just to remove all gems and start from scratch?也可以只删除所有宝石并从头开始吗? These are driving me nuts.这些让我抓狂。

I'm running OS X.我正在运行 OS X。

Assuming that gem clean (or sudo gem clean ) doesn't work, I would try the following to totally remove all gems from your system:假设gem clean (或sudo gem clean )不起作用,我会尝试以下操作以从您的系统中完全删除所有 gem:

You can see where gems have been installed by running the command:您可以通过运行以下命令查看已安装 gems 的位置:

gem env paths

To remove all the gems on your system, simply remove the folders returned by this command.要删除系统上的所有 gem,只需删除此命令返回的文件夹即可。

Additionally, on OSX Leopard, default gems are installed in this folder:此外,在 OSX Leopard 上,默认 gem 安装在这个文件夹中:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8

If this folder exists on your system, as before you can remove this folder to ensure all gems are deleted.如果您的系统上存在此文件夹,您可以像以前一样删除此文件夹以确保删除所有 gem。

You could also do the following to get rid of installed gems.您还可以执行以下操作来删除已安装的 gem。

gem list -d [gem name]
gem uninstall --install-dir [install directory] [gem name]

if the before mentioned things don't work, I had to do it myself today.如果前面提到的事情不起作用,我今天必须自己做。

I had a similar issue, but the root problem turned out to be gemspecs that were sticking around for some unknown reason.我有一个类似的问题,但根本问题原来是由于某种未知原因而遗留的 gemspecs。

After I thought I had uninstalled all gems:在我以为我已经卸载了所有宝石之后:

matt$ gem1.9 list
*** LOCAL GEMS ***
minitest (1.6.0)
rake (0.8.7)
rdoc (2.5.8)

No gems here:这里没有宝石:

matt$ ls -al /opt/local/lib/ruby1.9/gems/1.9.1/gems/
total 0
drwxr-xr-x  2 root  admin   68 Jul 23 14:54 .
drwxr-xr-x  8 root  admin  272 Mar  3 14:56 ..

There they are!他们在那里!

matt$ ls -al /opt/local/lib/ruby1.9/gems/1.9.1/specifications/
total 24
drwxr-xr-x  5 root  admin  170 Jul 23 14:54 .
drwxr-xr-x  8 root  admin  272 Mar  3 14:56 ..
-rw-r--r--  2 root  admin  129 Nov  1  2010 minitest.gemspec
-rw-r--r--  2 root  admin  121 Nov  1  2010 rake.gemspec
-rw-r--r--  2 root  admin  121 Nov  1  2010 rdoc.gemspec

Remove the gemspecs:删除宝石规格:

matt$ sudo rm /opt/local/lib/ruby1.9/gems/1.9.1/specifications/*

And now the gems are gone:现在宝石不见了:

matt$ gem1.9 list
*** LOCAL GEMS ***

I had a gem that would not die and had to go the "nuke everything" route by deleting all my gems with the command gem uninstall -aIx .我有一个不会死的 gem 并且必须通过命令gem uninstall -aIx删除我的所有 gem 来 go “nuke everything”路线。 Then just gem install <gemname> and I was back up and running.然后只需gem install <gemname>恢复运行。

If you have multiple versions of a gem, you will have to first do a clean up and then delete the final gem.如果您有一个 gem 的多个版本,您必须先进行清理,然后删除最终的 gem。

 gem cleanup <gemname>
 gem uninstall <gemname> --version

Update your version of ruby gems by running gem update --system and then, hopefully, gem uninstall xxx will work.通过运行gem update --system更新您的 ruby gems 版本,然后,希望gem uninstall xxx可以工作。 [It was a bug in older versions.] [这是旧版本中的错误。]

Check out RVM , it allows you to completely manage your ruby environment under your user rather than in a system directory.查看RVM ,它允许您在您的用户下而不是在系统目录中完全管理您的 ruby 环境。 I've found it much easier to manage ruby versions and gems using it.我发现使用它更容易管理 ruby 版本和 gem。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM