Installing Rails 2.2 on OSX Leopard
In my few spare moments, I like to hack Ruby on Rails. Non programmers are free to tune out at this point.
I recently tried to install and configure the recently released Rails 2.2. Among the changes therein, the MySQL driver is no longer included – you need to install the mysql gem.
The standard gem installation did not work:
$ sudo gem install mysql
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
After a bit of googling, it turns out you need to give a bit more information for this gem:
$ sudo bash -c "ARCHFLAGS='-arch i386' gem install mysql -- \
--with-mysql-config=/usr/local/mysql/bin/mysql_config"
Building native extensions. This could take a while...
Successfully installed mysql-2.7
1 gem installed
While this installed the gem, it still did not fix the problem:
!!! The bundled mysql.rb driver has been removed from Rails 2.2.
Please install the mysql gem and try again: gem install mysql.
rake aborted!
dlopen(/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9):
Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
Some further googling later, it transpires that you need to muck about with the dynamic link libraries:
$ sudo install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib \
/usr/local/mysql/lib/libmysqlclient.15.dylib \
/Library/Ruby/Gems/1.8/gems/mysql-2.7/mysql.bundle
$ sudo install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib \
/usr/local/mysql/libmysqlclient.15.dylib \
/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
These last two commands look very similar, but there’s a subtle difference between them: there are two different paths to separate instances of the libmysqlclient.15.dylib file.
And low and behold:
$ irb
>> require 'mysql'
=> true
And there was great rejoicing. Note that this solution is specific to Mac OSX Leopard. It will work for Tiger, apparently, but you need to change some of the paths in the last two commands.
We will now return you to your regular programming.
