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
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.

This article was posted by Matty on 2009-05-22 09:18:00 -0400 EDT