16

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

I've been following a bunch of guides to get set up, specifically these two here and 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.

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.8 because 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.

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

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

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


UPDATE:

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

GiH
  • 14,006
  • 13
  • 43
  • 56
  • http://stackoverflow.com/questions/4007074/uninstalling-rails-and-gems-getting-error-cannot-uninstall-check-gem-list-d/4007136#4007136 – Justin Soliz Oct 24 '10 at 04:53
  • turns out this question is a duplicate, but the answer was really hard to find so I'm keeping this open. http://stackoverflow.com/questions/3049244/geminstall-error – GiH Oct 24 '10 at 15:05

7 Answers7

36

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.

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):

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

Now all uninstalls should work!

Community
  • 1
  • 1
GiH
  • 14,006
  • 13
  • 43
  • 56
  • 1
    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
  • solution.. but I use rvm.. and install gems with sudo dont sounds like a good idea.. – Arnold Roa May 10 '16 at 17:14
20

Two things you should note when using rvm:

  1. You should NEVER use sudo to install gems, just do a gem install xxx

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


 rvm gemset use global
 gem uninstall xxx
calas
  • 1,603
  • 1
  • 12
  • 15
  • -1 I just get an eeror with that, Unrecognized command line argument: 'global' ( see: 'rvm usage' ) – Michael Durrant May 22 '11 at 15:20
  • 2
    After `rvm gemset use global` (and `gem cleanup ` or `gem uninstall `) make sure to switch back to your default gemset with `rvm gemset use default` – AlexChaffee Feb 21 '14 at 13:23
5

execute this either in irb or in a script proper:

`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
jacobsimeon
  • 2,012
  • 1
  • 18
  • 20
  • Nice script, it removed 90% of my gems successfully... but, its left ones like `bundler`, which gives the error "ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /Library/Ruby/Gems/1.8/bin directory.". I added `sudo` to the `gem uninstall`, but that still gives the error. It seems to be the install-dir option, its looking in bin but its not there. – Ian Vaughan Oct 21 '13 at 10:50
3

try this way :

sudo apt purge rails
Luan D
  • 1,320
  • 1
  • 13
  • 26
0

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

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

Waheed
  • 608
  • 1
  • 5
  • 20
0

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!

atw
  • 5,428
  • 10
  • 39
  • 63
0

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

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 Global rvm gemset name.

Justin Soliz
  • 2,781
  • 3
  • 25
  • 33
  • i moved that part of the question here http://stackoverflow.com/questions/4007171/rvm-and-global-gems – GiH Oct 24 '10 at 04:20