6

When I try to cleanup my rails versions with sudo gem cleanup rails

I get the following error:

Cleaning up installed gems...
Attempting to uninstall rails-2.3.5
Unable to uninstall rails-2.3.5:
Gem::InstallError: cannot uninstall, check `gem list -d rails`
Attempting to uninstall rails-1.2.6
Unable to uninstall rails-1.2.6:
Gem::InstallError: cannot uninstall, check `gem list -d rails`

gem list -d rails results in:

rails (2.3.8, 2.3.5, 1.2.6)
  Author: David Heinemeier Hansson
  Rubyforge: http://rubyforge.org/projects/rails
  Homepage: http://www.rubyonrails.org
  Installed at (2.3.8): /Library/Ruby/Gems/1.8
               (2.3.5): /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
               (1.2.6): /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8

  Web-application framework with template engine, control-flow layer,
  and ORM.

Any one know what's wrong?

Tian
  • 662
  • 2
  • 8
  • 23
  • dupe of http://stackoverflow.com/questions/1000731/getting-rid-of-ruby-gems-that-wont-die – x1a4 Jun 15 '10 at 21:39

2 Answers2

13

After some long searches it turns out the reason is because of a non-existent path. The cannot uninstall comes up because the system doesn't search /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8

On a granular level, instead of gem cleanup rails, you can simply use the uninstall command and type:

gem uninstall rails -i /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8

Then you might hit another problem related to a non-existent path, at which point, you should create a directory using the command:

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

Now all uninstalls should work well. I recommend doing a clean gem reinstall by performing the following functions:

create a list of all existing gems

gem list --no-versions | sed -e '/^(*|$)/d' > installed_gems

uninstall all existing gems

gem list | cut -d" " -f1 | xargs gem uninstall -aIx

reinstalling latest gems

cat installed_gems | xargs sudo gem install

Community
  • 1
  • 1
Tian
  • 662
  • 2
  • 8
  • 23
  • Very helpful. To run the uninstall script though I had to alternate between adding -i /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 and not until all gems were successfully removed. – Alexander Ljungberg Sep 26 '10 at 16:16
  • I used: gem list --no-versions | xargs sudo gem uninstall -aIx -i /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 **or** gem list --no-versions | xargs sudo gem uninstall -aIx -i /Library/Ruby/Gems/1.8 depending on where the Gem was installed. – terrace May 13 '11 at 02:14
  • I just spent the last hour looking through different alternatives and this is the one that worked for me. btw, I DID NOT USE SUDO. God bless you, I'd give you 50 votes if I could – Abe Petrillo Jan 30 '12 at 17:01
1

Check out http://gabrito.com/post/mac-os-x-gem-cleanup-failing, proposing:

sudo sh -c 'GEM_HOME=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 gem cleanup'
Ruben Verborgh
  • 3,545
  • 2
  • 31
  • 43