Tian
Tian

Reputation: 672

Gem::Install Error

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?

Upvotes: 6

Views: 3345

Answers (2)

Tian
Tian

Reputation: 672

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

Upvotes: 13

Ruben Verborgh
Ruben Verborgh

Reputation: 3665

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'

Upvotes: 1

Related Questions