Installing the mysql rubygem on Leopard

There are so many sites offering suggestions on how to get the mysql rubygem working on Mac OS X Leopard. None of them worked for me. Here’s how I got the gem installed.

After attempting to install the gem normally, with sudo gem install mysql (which bombs out), go into /Library/Ruby/Gems/1.8/gems/mysql-2.7 or wherever it tried to install the gem. Add the line

#define ulong unsigned long

near the top of the file

Repackage the gem by issuing sudo gem build mysql.gemspec

Then install with

sudo env ARCHFLAGS="-arch i386" gem install --local mysql-2.7.gem -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

You’re done. You may not need to wrap the gem install command with the env command.