Installing ruby mysql gem in OSX 10.5 (Leopard)

November 9, 2007

It took awhile, but I've finally switched over to OSX - and from what I can tell by googling for "OSX Ruby mysql gem", have gone through what seems to be an initiation.

There are many, many, many posts on how to make it install - and most of them didn't work for me. I did get it to work though and actually quite easily once i figured out what to do, so I figured I'd post yet another blog on the subject detailing how it worked, for me.

sudo su
ARCHFLAGS="-arch i386" gem install mysql -- \ 
--with-mysql-dir=/usr/local/mysql

This made it install, but requiring mysql caused it to explode.. to fix that:

install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib \
/usr/local/mysql /lib/libmysqlclient.15.dylib \ 
/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle

The install_name_tool changes where the mysql.bundle looks for the dylib file - by default it was looking in mysql/lib/mysql instead of mysql/lib. The gem install command that worked I found on wishingline.com and some info on the install_name_tool fix was found in this thread.

Hopefully this will be helpful for somebody else trying to install the ruby mysql gem on leopoard!

Update: Rein has posted a cleaner solution.