How to Fix That Rubygems Mess on Leopard

| Comments

I love Leopard and I love my Mac. I think Apple made the right decision by bundling Ruby and Rails with Leopard. However, I believe they screwed up big time in the execution.

Leopard’s Rails installation worked great until I updated Rubygems with sudo gem update –system. After I did that, most of my gems were broken, and reinstalling them didn’t help. According to Google, I was not alone.

The right thing to do for Apple would have been to ship Leopard with MacPorts and have Ruby and Rubygems installed through it. Unfortunately, they had to reinvent the wheel…

This tutorial will guide you through fixing that mess. We will be reinstalling Ruby and Rails with MacPorts and deleting the original Ruby installation to avoid conflicts.

You might want to backup your system before proceeding as I cannot be held responsible if something goes wrong (my lawyer made me write that). I tried it on 2 different machines and it worked fine for me.

So let’s get started already!

Step 1: Install MacPorts

Start by installing MacPorts if you don’t already have it on your machine. It’s an awesome must-have piece of software anyways! It’s super easy to install with the Leopard package.

Step 2: Install XCode 3.0

You must also have XCode 3.0 installed. It’s a huge download so you might want to install it from your Leopard DVD. It’s in _/Optional Installs/Xcode Tools/XcodeTools.mpkg _

Installation will take some time, so go read Digg, Reddit, or install Defensio on your blog!

Step 3: List your gems

Get a list of your installed gems and save it to a text file somewhere. You will need to reinstall them! gem list > ~/Desktop/installed_gems.txt

Step 4: Clean up your Mac

In order to avoid conflicts with your original Ruby installation, I recommend you simply delete it. To do so, run these commands (I know… scary stuff!):

sudo rm -r /System/Library/Frameworks/Ruby.framework/
sudo rm -r /Library/Ruby
sudo rm /usr/bin/ruby
sudo rm /usr/bin/gem

Step 5: Install Ruby and Rubygems with MacPorts

If you don’t perform step 4, you will run into problems at step 6.

Now go ahead and install Rubygems through MacPorts. It will automatically install Ruby (and many other things) as it’s a dependency. The command is: sudo port install rb-rubygems

This one will also take a while… When it’s done, update Rubygems: sudo gem update --system

Step 6: Install Rails

At this point, you should have a brand new Ruby and Rubygems installation working! That wasn’t too hard was it?

Now let’s install Rails.

  • For Rails 1.2.6, run sudo gem install rails -v 1.2.6
  • For Rails 2 (aka latest-and-greatest), run sudo gem install rails

Note that recent versions of Rubygems no longer requires the –include-dependencies parameter.

Step 7: Reinstall your gems

Now’s the time to reinstall your original gems.

To reinstall the gems that shipped with Leopard, execute this command:

sudo gem install RedCloth acts_as_ferret mongrel fcgi capistrano ruby-openid ferret dnssd hpricot sqlite3-ruby libxml-ruby termios`

Then, you might want to reinstall the other gems you had. The list is on your desktop in installed_gems.txt.

That’s it! You now have a more standard and less prone to problems Rails stack on your Mac!

EDIT: This is old. It’s probably not a good idea to follow this as of 2012.