How can I remove a default gem? ! want to uninstall a gem 1.7.7 version of json

坚强是说给别人听的谎言 提交于 2019-11-27 03:52:01

问题


I have the same rails app in OSX and Ubuntu, I want to use Zeus to speed up my rspec. In Ubuntu, Zeus starts Ok, but in OSX it always be crashed. At last I find the issue, https://github.com/burke/zeus/issues/237#issuecomment-18700462 the difference between OSX and Ubuntu is the version of json gem. I use gem list | grep json Ubuntu shows

json (1.8.1, 1.8.0, 1.5.3)
json_pure (1.5.3)
json_spec (1.1.1)
jsonpath (0.5.3)
multi_json (1.8.2, 1.7.8, 1.0.3)

Mac shows

json (1.8.1, 1.7.7)
json_spec (1.1.1)
jsonpath (0.5.5, 0.5.3)
multi_json (1.8.2, 1.7.8)

so I want to uninstall 1.7.7 version of json gem to make zeus start, but

gem uninstall json -v 1.7.7
ERROR:  While executing gem ... (Gem::InstallError)
gem "json" cannot be uninstalled because it is a default gem

What should I do?


回答1:


So based off what I can tell there is no easy command that can move the gemspec file from the default folder to the non-default folder. This is a good thing from what I can tell but here are the instructions on how to do this by hand.

  1. Find the location of the default spec. The easiest way is to go into irb and run the following command

    irb(main):001:0> File.join Gem::Specification.default_specifications_dir
    => "/Users/newdark/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/specifications/default"
    

This is the line of code that builds the gemspec path https://github.com/rubygems/rubygems/blob/v2.6.13/lib/rubygems/installer.rb#L420

  1. Once you get the file path you just need to move the gem name and version from the default folder to the parent folder.

    $ cd /Users/newdark/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/specifications/default
    $ mv json-1.7.7.gemspec ../
    

if you do gem list -d you should no longer see the words Installed at (default) next to the gem version json-1.7.7. you can then run gem uninstall json -v 1.7.7 with out it fighting you. If you want to undo all this just run gem install json -v 1.7.7 --default




回答2:


I have been experiencing a problem with default versions of gems, and the accepted answer did not work for me. What worked for me was to install the same version as the default, but without the default flag, and then uninstall it.

gem install json -v '1.7.7'

Then once that is finished:

gem uninstall json -v '1.7.7'



回答3:


may be this will help you....

bundle exec gem uninstall GEM_NAME

if above cmd not work then try this

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

if above both are fails then try this

go to your rvm dir.. where all gems are install then manually remove that gem which you want.. such as in my case my gem dir location is /home/user_name/.rvm/gems/ruby-1.9.3-p194/gems



来源:https://stackoverflow.com/questions/20945110/how-can-i-remove-a-default-gem-want-to-uninstall-a-gem-1-7-7-version-of-json

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