Cleaning up old Ruby gems

I was doing some experiments with a number of Ruby gems, and installed several gem versions as part of my testing. The gem utility has a slew of useful built-in options, one being “cleanup”. When gem cleanup runs, it will remove all gems that are older than the the latest gem version. So given a gem that has two versions:

$ gem list httplib

*** LOCAL GEMS ***

httplib (2.5.1, 2.5)

We can first run gem cleanup in dry-run mode to see what would be removed:

$ gem cleanup -d
Cleaning up installed gems…
Dry Run Mode: Would uninstall httplib-2.5
Clean Up Complete

Once we are happy with the results, we can run gem cleanup to actually remove the old gems:

$ gem cleanup -v
Cleaning up installed gems…
Attempting uninstall on httplib-2.5
Successfully uninstalled httplib version 2.5
Clean Up Complete

Ruby is an amazing language, and the more I read about it the more I like it.

One Comment

Ken Nordquist  on May 27th, 2009

Nice post Matty. I like your dry run advice. I also wrote a couple of blog posts about gem cleanup… Geekystuff: Painless Cleanup of Your Ruby Gems and GeekyStuff – Painlessly Remove All Ruby Gems.

As a Linux (*nix) geek, I am enjoying perusing your site… keep up the good work!

-Ken

Leave a Comment