If you have been using Ruby for a while you may have quite a large collection of gems. Chances are, you have a number of different versions of each gem. The following are simple ways to clean out any old versions of your gems:

Note: Depending how you have your dev environment setup you may need to use the ‘sudo’ command.

First, let’s find out which gems you currently have installed.

The output should be something like this:

Great! Let’s do some ‘proper’ housekeeping before we move any forward.

Output should include all outdated gems, let’s update them:

Note: I like to use the –no-document option for a quick gem install, using this option will not install the documentation of the gem. Saving disk space.

Finally, let’s update RubyGems:

After updating, let’s begin the 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:

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

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

Other “advance” options; ha. To remove any given gem:

To remove a specific version of a gem:

Now to remove all versions less than X.X.X:

Congratulations! You’ve learned how to keep your shit clean.