Uninstalling rails and gems, getting error "cannot uninstall, check 'gem list -d …'

妖精的绣舞 提交于 2019-12-28 10:12:23

问题


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?


回答1:


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!




回答2:


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



回答3:


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



回答4:


try this way :

sudo apt purge rails



回答5:


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.




回答6:


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

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




回答7:


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!



来源:https://stackoverflow.com/questions/4007074/uninstalling-rails-and-gems-getting-error-cannot-uninstall-check-gem-list-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!