Here's a little tip if you can't figure out why you can't seem to uninstall or cleanup your rubygems on Mac OS X.

It seems as though there are 3 possible directories where gems are installed in OS X.

  1. ~/.gems

    This is where you can install gems that are only available to you. As far as I can tell this is where gems will end up by default if you don't use sudo before you gem install. It's probably not a big deal to have your gems go here unless you do what I did (see below).

  2. /Library/Ruby/Gems/

    This is where gems will be installed if you sudo gem install them and they'll be accessible to everyone using the machine.

  3. /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/

    This is where Apple has their gems the come installed by default. From everything I read you really shouldn't fuck with these.

Now for the most part installing in 1 or 2 should never be a problem, however if you happen to accidentally install in both 1 and 2, like I did, you'll run into some weird things. "Why would you install your gems into both places?", you might ask. Well, I'm not really used to using a Mac so I initially ran sudo gem install merband then just did gem update merb without sudo because I forgot. Rubygems helpfully informed that I did not have permission to install the gem in /Library/Ruby/Gems and then went right ahead and installed in ~/.gems instead. I'm not really sure if this would have caused a problem or not but I thought it was pretty stupid to have gems in two different places so I though I'd just uninstall merb and start from scratch. And that is where the fun began.

Rather than go through all the shit I went I through, here's what I discovered:

If you have the different versions of the same gem (i.e. merb-1.0 and merb-1.0.3) in both your local and global gem directories rubygems may not have a clue which one you mean. I tried running gem uninstall merb and got a message saying 1.0.3 was gone but sure enough it was still in ~/.gems. I then tried sudo gem uninstalling which would say it was gone but all the gems were still around.

Anyway, this kind of craziness kept happening until I discovered the -i switch for the gem uninstall command. This basically tells rubygems what directory you want it to look in when attempting to uninstall a gem. Since I wanted everything out of my ~/.gems directory I tried gem uninstall thor -i ~/.gems/ruby/1.8 as test and lo and behold it was actually removed. So I wrote a little bash "script" that would then remove everything from .gems:

    GEMS=`gem list --no-versions`
    for x in $GEMS ; do sudo gem uninstall $x -i ~/.gem/ruby/1.8/; done

You'll still have to answer 'Y' to all the dependency questions with this but it did manage to remove all my local gems and that, in turn, put my gem install back on track.