Monday, March 22, 2010

MacPorts headaches... solved!

So I finally found a way to solve all those MacPorts headaches, thanks to Erik Michaels-Ober, a friend of a friend. As I and many folks have learned, Mac OS X is less than standard *Nix when it comes to setting up their directories, and it doesn't take kindly to co-creation of a parallel directory tree. MacPorts puts things in the (*Nix) standard /opt directory, but once that's done, you get path and name clashes.

I've seen bits and pieces of a solution as noted in my previous posts, but they really didn't fix the problem. And of course, there's the issue that's been reported elsewhere that upgrading to Snow Leopard can wreak havoc on a development setup.

So following Eriks' instructions, here's what I did:
  1. I wiped my system clean and installed Snow Leopard from scratch. You may be able to just do an upgrade, but I chose to go with a clean system.
  2. Install the XCode Developer Tools that come with Snow Leopard (or download the latest version from the Apple website. Warning: it’s a big file).
  3. Remove all the pre-installed rubygems from your system. You can do this using the “gem uninstall” command, or brute force. I chose the brute force method, but only after creating a copy before I did the deletion, just in case. Once I knew it worked, I got rid of my copies.
    rm -rf /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/*

    rm -rf /Library/Ruby/Gems/1.8/*
  4. Install MacPorts (see the MacPorts installation page).
  5. Make sure you’re running MacPorts version 1.8.2 (type: port version). If not, run the command:
    sudo port selfupdate
  6. Install the MacPorts version of ruby itself:
    sudo port install ruby
  7. Install the MacPorts version of rubygems:
    sudo port install rb-rubygems
  8. Install the MacPorts version of git:
    sudo port install git-core
  9. Upgrade to the latest version of rubygems:
    sudo gem update --system
  10. Make sure you’re running rubygems version 1.3.5 (type: gem -v). If not, run the command: update_rubygems
  11. Install all the gems you want (rails, heroku, etc.). They will be installed into /opt/local/lib/ruby/gems/
I set up my machine about a month ago and it's been working fine ever since.