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.

Related Posts:


6 Responses to “Installing Rails 2.2 on OSX Leopard”

  • Ron Sweeney Says:

    thank you!

  • jerkface Says:

    hi i followed your instructions but i still ended up with an error:
    dyld: lazy symbol binding failed: Symbol not found: _mysql_init

    Referenced from: /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
    Expected in: dynamic lookup

    dyld: Symbol not found: _mysql_init
    Referenced from: /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
    Expected in: dynamic lookup

  • Anthony Altemara Says:

    Thank you! I’m up and running on the Mac now with 2.2!

    Any optimization tips? Next step, I optimize this app!

  • steve Says:

    Ron, you’re welcome – glad you found it useful.

    jerkface, I’m afraid that that’s not an issue that I have run across – the above process worked for me as documented.

    Anthony, delighted to hear it. Don’t have anything particularly enlightening to impart on optimization, I’m afraid.

  • Michael CP Says:

    THANKS!!! it worked beautifully!

  • steve Says:

    Michael, glad to be of service.

    I post this kind of stuff as much as an aide mémoire as anything, but it’s always great to find that others get some value.

Leave a Reply