MySQL Gem on Snow Leopard

Snow Leopard does not have the mysql gem installed, and my last solution for installing it only work in OS X prior to 10.6.4; therefore, when you see the following error:

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

Install the mysql gem with these steps:

  1. Download and install the latest version of MacPorts if not already installed
  2. Run the following commands to install mysql5 and the associated ruby gem

# sudo port install mysql5-server
# sudo env ARCHFLAGS="-arch x86_64" gem install mysql

Fixing MySQL Gem on Snow Leopard

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