22

I've got a few ruby gems that won't go away.

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. But gem uninstall doesn't work. It continually shows up in 'gem list' but can't uninstall it from either gem uninstall, or 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.

Also is it possible just to remove all gems and start from scratch? These are driving me nuts.

I'm running OS X.

holden
  • 13,471
  • 22
  • 98
  • 160

7 Answers7

31

Assuming that gem clean (or sudo gem clean) doesn't work, I would try the following to totally remove all gems from your system:

You can see where gems have been installed by running the command:

gem env paths

To remove all the gems on your system, simply remove the folders returned by this command.

Additionally, on OSX Leopard, default gems are installed in this folder:

/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.

Olly
  • 7,732
  • 10
  • 54
  • 63
  • one follow up question... when i install gems via rails with rake gems:install will they get installed properly? or should i also run sudo rake gems:install? – holden Jun 16 '09 at 11:35
  • I guess that depends which Ruby installation you're using and how that was installed. If you installed it from source, chances are you'll need to run `sudo rake gems:install`. I'd generally favour the sudo option in most cases – Olly Jun 16 '09 at 13:32
13

You could also do the following to get rid of installed gems.

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.

Bitterzoet
  • 2,752
  • 20
  • 14
  • 2
    That's the only thing that actually helped me. All the other stuff didn't change anything – mac Nov 20 '16 at 07:58
  • yep, I had the ffi gem completely unwilling to to leave its entrenched position on my machine until I did this. – Noel Apr 26 '23 at 05:15
8

I had a similar issue, but the root problem turned out to be gemspecs that were sticking around for some unknown reason.

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 ***
Matt Kent
  • 146
  • 2
  • 3
3

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. Then just gem install <gemname> and I was back up and running.

tylermilner
  • 434
  • 4
  • 7
2

If you have multiple versions of a gem, you will have to first do a clean up and then delete the final gem.

 gem cleanup <gemname>
 gem uninstall <gemname> --version
user3245240
  • 265
  • 4
  • 10
0

Update your version of ruby gems by running gem update --system and then, hopefully, gem uninstall xxx will work. [It was a bug in older versions.]

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
rogerdpack
  • 62,887
  • 36
  • 269
  • 388
0

Check out RVM, it allows you to completely manage your ruby environment under your user rather than in a system directory. I've found it much easier to manage ruby versions and gems using it.

Dan McNevin
  • 22,278
  • 5
  • 35
  • 28