Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uninstall all installed gems, in OSX?

Tags:

ruby

rubygems

People also ask

Where are gems installed Macos?

By default, binaries installed by gem will be placed into: /usr/local/lib/ruby/gems/3.1.

How do you clean RubyGems?

To remove older gems we use the clean command: The cleanup command removes old versions of gems from GEM_HOME that are not required to meet a dependency. If a gem is installed elsewhere in GEM_PATH the cleanup command won't delete it. If no gems are named all gems in GEM_HOME are cleaned.


Rubygems >= 2.1.0

gem uninstall -aIx

a removes all versions
I ignores dependencies
x includes executables

Rubgems < 2.1.0

for i in `gem list --no-versions`; do gem uninstall -aIx $i; done

You could also build out a new Gemfile and run bundle clean --force. This will remove all other gems that aren't included in the new Gemfile.


A slighest different version, skipping the cut step, taking advantage of the '--no-version' option:

gem list --no-version |xargs gem uninstall -ax

Since you are removing everything, I don't see the need for the 'I' option. Whenever the gem is removed, it's fine.


First make sure you have at least gem version 2.1.0

gem update --system
gem --version
# 2.6.4

To uninstall simply run:

gem uninstall --all

You may need to use the sudo command:

sudo gem uninstall --all

Use either

$ gem list --no-version | xargs gem uninstall -ax

or

$ sudo gem list --no-version | xargs sudo gem uninstall -ax

Depending on what you want, you may need to execute both, because "gem list" and "sudo gem list" provide independent lists.

Do not mix a normal "gem list" with a sudo-ed "gem uninstall" nor the other way around otherwise you may end up uninstalling sudo-installed gems (former) or getting a lot of errors (latter).


If you are using Rubygems version 2.1.0 or later, you can try: gem uninstall --all.


And for those of you who are here because you want to remove all gems with a certain prefix (ahem I'm looking at you aws-sdk!) you can run something like this:

gem list --no-version | grep "aws-sdk-" | xargs gem uninstall -aIx

Obviously put in your query instead of aws-sdk-. You need the -I in there to ignore dependencies.

Adopted form Ando's earlier answer