Fixing MySQL Gem on Snow Leopard

Sun, Sep 6, 2009 One-minute read

NOTE: See my latest post for a solution for OS X 10.6.4 and later

A fresh Snow Leopard (OS X 10.6) install does not have the mysql gem installed, and installing it fails because of missing header files:

Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install mysql
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h

To correctly install the mysql gem:

  1. Download and install the MySQL package.
  2. Install XCode that’s bundled with Snow Leopard
  3. Install the gem for your architecture (use -arch i386 if you have an Intel Core Solo or Intel Core Duo processor):
$ sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql-5.1.38-osx10.5-x86_64/bin/mysql_config