Installing MySQL Ruby bindings on OS X Leopard (with MacPorts)
24 11 2007The upside of Leopard is that it comes pre-packaged with Ruby 1.8.6, Rails 1.2.3, and Capistrano. However, most Rails developers utilize MySQL for local development (if not also production) and a lot of us are in the habit of utilizing MacPorts to get it.
With the OS installation of Ruby and the MacPort installation of MySQL, it can be a bit of a challenge to get the correct Ruby bindings for MySQL without stomping on top of the existing Ruby installation. So, in short, here’s the answer:
sudo port install mysql5 +server
sudo env ARCHFLAGS=”-arch i386″ gem install mysql \ –with-mysql-include=/opt/local/include/mysql5/mysql \ –with-mysql-lib=/opt/local/lib/mysql5/mysql
That should be two lines up there, both starting with sudo.
Now that we’ve got the solution out of the way, I’ll go ahead and throw up the explanation for the *cough*upper*cough* 1% of you that might care. The MacPorts installation builds your MySQL setup in the /opt directory on our root disk, by default. Further, the current mysql port does not install all of the lib and include files inside of one, nice subdirectory, but rather in subdirectories of /opt/local/lib and /opt/local/include, respectively. All you’ve got to do is let your GEM installation know where to look, while forcing an i386-compatible architecture for the build.
Lovely, huh? Go forth and conquer.
Line 01 should not have a hypen at the end.
Thanks TCS. I updated the post and added the “\” markers to the end of lines to represent that those lines should not be broken.
Another note worth mentioning, WordPress turns double hyphens into a single dash character in the code, so those should also be hyphen-hyphen options on the gem install command.