Take the 2-minute tour ×

It seems that ruby 2.0.0 has added "default" gems to the mix and makes them non removable by gem uninstall.

How can you remove all non default gems?

share|improve this question
Can you provide example of gems & how you installed Ruby 2.0 (manually? rvm?) –  Marc-André Lafortune Feb 26 '13 at 22:54
I used rbenv to install ruby 2.0.0-p0. Gems that are "default" for me at least are: bigdecimal 1.2.0, io-console 0.4.2, json 1.7.7, minitest 4.3.2, psych 2.0.0, rake 0.9.6, rdoc 4.0.0, test-unit gem uninstall json errors with gem "json" cannot be uninstalled because it is a default gem. –  Nathan Lilienthal Feb 26 '13 at 23:20
Sorry, misunderstood. I never delete gems, not sure one would. Why do you need anything else than gem cleanup? –  Marc-André Lafortune Feb 27 '13 at 3:11
Sometimes I just want to get rid of things. Cleanup is probably what most people need most of the time. There are times however I want to get rid of all gems to test bash scripts that need to install things like gems. –  Nathan Lilienthal Feb 27 '13 at 3:41
rvm has gemsets, not sure about rbenv –  Marc-André Lafortune Feb 27 '13 at 4:15
show 1 more comment

4 Answers

up vote 38 down vote accepted

I used this one line script.

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

It ignores default gem errors and just proceeds. Simple and self-evident.

share|improve this answer
That's a simpler solution for this problem, assuming rubygems continues to work this way :) –  Nathan Lilienthal Feb 28 '13 at 16:30
Nice work! You don't see a lot of terse shell commands posted using a loop. –  james_womack Apr 18 '13 at 17:39
Does not work. still get 'cannot be uninstalled because it is a default gem' errors. –  Nippysaurus Aug 3 '13 at 4:23
@Nippysaurus It's normal. You can just ignore it. If you mean the command stops after the first error, type set +e and try again. –  ihji Aug 20 '13 at 8:57
@ihji would know if this works gem list --no-version | awk 'NR>1{ print $(NF-1) }' | xargs gem 2>/dev/null uninstall -aIx it doesn't error but it also doesn't uninstall the gems. I assume the command still stops executing when error occurs (even if it gets redirected) –  Integralist Dec 11 '13 at 12:04
add comment

I wrote a script in ruby to remove all non default gems.


This is needed now because unlike before 2.0.0 some gems are labeled "default" with the installation of ruby, and cannot be uninstalled with gem uninstall. This makes the previously popular methods for deleting all gems not work.

For reference here it is.

share|improve this answer
The supplied link no longer exists. "OH NOES, 404". Is there somewhere else this script exists, or is the "for reference" line the entire script? –  Br.Bill May 1 '13 at 23:58
Thanks. I changed my username. The URL is fixed. –  Nathan Lilienthal May 9 '13 at 12:50
add comment

First, go to the gems directory Like ../ruby/2.0.0-p195/lib/ruby/gems/2.0.0/specifications
You will find a directory named default, which including all the default gems shipped with ruby 2.0

Move all the *.gemspec stored in default dir to specifications dir and remove the empty default dir.

Then you can do whatever you want like old days.:-)

share|improve this answer
What is the specification directory used for now? It's in the load path I assume? –  Nathan Lilienthal Jul 1 '13 at 22:06
add comment

I have not yet found a better answer than to exclude the "default" gems:

/usr/local/bin/gem list --no-versions | \
grep -v -E "(bigdecimal|io-console|json|minitest|psych|rake|rdoc|test-unit)" | \
xargs --no-run-if-empty /usr/local/bin/gem uninstall --executables --user-install --all --force
share|improve this answer
This code is assuming you installed ruby 2.0 from source on Linux. –  Kevin Feb 11 at 18:14
add comment

Your Answer


