Installing PostgreSQL and Mysql and the Ruby gems on Snow Leopard

Things have gotten a lot simpler since the write-up I gave for Leopard.

Again, Snow Leopard comes with Ruby preinstalled, and I strongly recommend that you stick with that version rather than using the macports Ruby – no need to have two versions on your system.

Most of us use macports to install postgresql & mysql for use with rails, which I recommend; the ports have changed slightly since Leopard, now you should just use: -

sudo port install mysql5-server
sudo port install postgresql84-server

Those -server ports are actually for the LaunchDaemon files, which you want, but they also depend on the underlying database server port which you need. If you aren't ready for PostgreSQL 8.4 yet, you can use postgresql83-server or postgresql82-server instead.

Follow the instructions the -server port build prints out to set the clean databases up and install the LaunchDaemon files to start the actual database servers.

You should also add the macports postgresql bin directory to your path. Restart your console session (close & reopen the terminal tab) to pick up the new PATH, or set it manually too.

You no longer need to specify paths to the macports stuff when installing the database gem bindings, even if you're using the OS X Ruby with the macports database drivers. Just use:

sudo env ARCHFLAGS="-arch x86_64" gem install pg
sudo env ARCHFLAGS="-arch x86_64" gem install mysql

A couple of things to note here. First, I'm explicitly specifying that we want the x86_64 build, because that's what macports will have built the databases for – assuming you have a 64-bit capable Snow Leopard. In my Leopard instructions I didn't have to make any assumptions – I used the `uname -m` command to find out what kernel architecture you have.

Unfortunately for Snow Leopard this doesn't give the results we want. With Snow Leopard although the OS itself supports 64-bit, and most of the applications are built for 64-bit mode, the kernel itself defaults – on everything except modern XServes – to 32-bit mode, to give various driver/utility vendors time to write 64-bit versions of their stuff.

That's all fine – oddly, the mostly-32 bit kernel will still run all the 64-bit apps – but unfortunately `uname -m` on OS X will return the kernel architecture, not the application architecture, so it will say “i386” instead “x86_64”, which is what we actually want to build with.

So I've just put in the explicit ARCHFLAGS=“-arch x86_64” above instead of ARCHFLAGS=“-arch `uname -m`”. You can use the latter if you're not building for 64-bit database drivers or are on an ancient PowerPC machine.