Installing the MySQL Ruby Gem on OS X 10.6 (Snow Leopard)
UPDATE: The advice in this post may work for some people, but I didn’t have complete luck until I installed MySQL via MacPorts, and then completely reinstalled Ruby and RubyGems via the Instructions at Hivelogic. Feel free to post a comment if you’re still having trouble.
Holy jumping crap am I ever sick of installing the MySQL gem. If I never have to do it again, it will be too soon. That being said, here’s what you get (as usual) if you
sudo gem install mysql
on Snow Leopard:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
*** 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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/ruby
--with-mysql-config
Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
This time it’s pretty simple. First of all, get rid of any old versions you have kicking around
sudo gem uninstall mysql
Next, install the newest MySQL package. Make sure you get the 64-bit version. For me it was 5.1.38. After that, and here’s the important, install Xcode from your Snow Leopard disc. Don’t skip this step! You may also need to update your RubyGems install:
sudo gem update --system
Finally, you just need to install the gem telling it where your config file is:
sudo gem install mysql -- --with-mysql-config=/usr/local/mysql-5.1.38-osx10.5-x86_64/bin/mysql_config
And that ought to do it!
