How to: Clean up old gems

If you have been using Ruby for a while you may have quite a large collection of gems. And, chances are, you have a number of different versions of each gem. There is a simple way to clean out any old versions of gems.

Just use:

sudo gem cleanup

The cleanup will respect any dependencies on old versions that a gem might have, asking you about each as it goes. If you just want to see a list of what would be removed (without actually removing them) you can use:

sudo gem cleanup -d

You can also cleanup just a specific gem by specifying its name:

sudo gem cleanup moredown

That will remove all but the latest version (again, respecting any dependencies on older versions) of the given gem.

For more information check out the RubyGems Command Reference.