Monday, March 16, 2009

Ruby on Rails on Mac (AGAIN)

I've set up RoR on my Mac about three times in the past month. I decided to buy a new hard drive for my old MBP. How old? One of the first ones off the boat (February 2006). I only bought it right after it came out because someone stole my old iBook out of my FEMA trailer and I needed a development box quickly. It worked well for a while but I decided to install a new HD because I was worried the old one might give up the ghost on me soon. So with installing Leopard on my MBP, installing the new HDD and now buying my new hotness, the LATE 2008 MACBOOK PRO, I've had to configure a new box for Rails development so many time you'd think I could do it with my eyes closed.

Not that I despise it, the installation is a snap, but there are always a few things I seem to forget, so here they are in the hopes that someone googling around might find it useful (and I know where to look!).

As my friend Luis suggests, the first thing you should do is preserve the Rubygems that come with your computer by setting GEM_PATH to their original location. Follow the link, its crucial in my opinion.

If you are forced to do development using MySQL, you have to do a few things because Leopard comes with PostgreSQL support only. There are two options for this. Download the MySQL 5 package from (get the x86-64 version if you have the new hotness), or follow these excellent instructions on hivelogic for how to do it the command line way. Either way is fine, the former gives you a MySQL prefpane that you can use to start and stop the server, the latter gives you some knowledge of what's going on behind the scenes of your MySQL installation, as well as lets you upgrade it whenever there is a new binary rather than waiting for someone to package it up for you.

Installing the MySQL gem seems to be goofy as hell, you usually can't just do

sudo gem install mysql

so what I do is

\m/ sudo su

\m/ ARCHFLAGS='-arch x86_64' gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Be sure to change ARCHFLAGS to suit your fancy i386 for 32-bit for example.

Finally, JRuby. You can now use Macports to install JRuby which is awesome.

\m/ sudo port install jruby

You still need to set JAVA_HOME after you do this. In ~/.*your_favorite_shell*_profile add

export JAVA_HOME='/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home'

and you should be fine. BUT, to install rjb (Ruby Java Bridge) it often gives you a grammatically awful error message, "JAVA_HOME not setted" despite it BEING SETTED. So I usually just export JAVA_HOME directly in my terminal session so that it has an easier time finding that shell variable.

I think that's everything that needs to be done to a Leopard box to do RoR development with a MySQL database and JRuby. I may have missed something, I wrote this at the end of the workday.