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

左心房为你撑大大i 提交于 2019-11-28 05:06:27
GiH

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!

calas

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

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

try this way :

sudo apt purge rails

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.

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

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

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!

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