How can I remove a default gem? ! want to uninstall a gem 1.7.7 version of json
Solution 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.
-
Find the location of the default spec. The easiest way is to go into
irb
and run the following command:irb(main):002:0> Gem.default_specifications_dir => "/Users/user/.rubies/ruby-2.5.7/lib/ruby/gems/2.5.0/specifications/default"
For older rubygems it's:
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
-
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
Solution 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'