Rails MySQL and Leopard

September 29th, 2007

UPDATE:

I didn't know about the ARCHFLAGS environment variable, this is a less intrusive way (thanks to Sebastian for pointing this out):

sudo su -
ARCHFLAGS='-arch i386' gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

(sudo su - asks you for your normal password not the root password)

I'm using the stock ruby environment on Leopard and the MySQL Package from http://www.mysql.com. Unfortunately installing the mysql driver as a gem doesn't work out of the box and the default mysql driver that comes with rails seems to be quite buggy.

To get it working we have to remove all occurrences of "-arch ppc" in rbconfig.rb, otherwise it tries to compile the mysql driver for the powerpc plattform as well, what we don't want (assuming you have an Intel Mac, otherwise remove "-arch i386").

We also have to tell the driver where to find the the mysql libs, includes and so on. We can do this by specifying where the path the mysql_config command.

cd /usr/lib/ruby/1.8/universal-darwin9.0/
sudo mv rbconfig.rb rbconfig.rb.orig
sudo sed "s/-arch ppc//g" rbconfig.rb.orig > rbconfig.rb
sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

(if you use a PPC Mac replace ppc with i386 on line 2)

3 Responses to “Rails MySQL and Leopard”

  1. Charles Harvey Says:
    Thanks Philipp this worked great. I had to add a couple of lines to get it to work on my machine see below. cd /usr/lib/ruby/1.8/universal-darwin9.0/ sudo mv rbconfig.rb rbconfig.rb.orig sudo chmod 777 /usr/lib/ruby/1.8/universal-darwin9.0/ sudo sed "s/-arch ppc//g" rbconfig.rb.orig > rbconfig.rb sudo chmod 755 /usr/lib/ruby/1.8/universal-darwin9.0/ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
  2. Sebastian Says:
    I came up with a "less intrusive" solution: http://www.notsostupid.com/blog/2007/10/25/ruby-leopard-and-gems/ It boils down to sudo bash -c "ARCHFLAGS='-arch i386' gem install mysql ..."
  3. Thiago Says:
    Hi Philipp, tried to use your solution but got the following error. I'm on a Leopard clean install. ---------------------- Building native extensions. This could take a while... ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError) ERROR: Failed to build gem native extension. ruby extconf.rb install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config extconf.rb:1: command not found: /usr/local/mysql/bin/mysql_config --cflags *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. (...) ---------------------- Ideas? Thank you so much! :)

Leave a Reply