A recent opportunity made me dust off my development skills and I decided to use Ruby on Rails as the framework of choice.
I’m happy with Ruby 1.8.7 for now (comes with Mac OS X Snow Leopard), but I had to update Rails to version 3, which was a painless process. After installing MySQL 5.5.10 (dumping MAMP for now), I installed the ruby gem for MySQL:
$ sudo gem install mysql2
You may want to run this too, although the first one should do the trick:
$ sudo gem install mysql
A quick test got me this piece of error:
LoadError: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle Reason: image not found – /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require’ from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require’ from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require’ from (irb):1
You can never have a perfect installation experience. Can you?
A thread on Stack Overflow guided me to this solution:
$ sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
Note: As it happened with me, you might have the same problem that MySQL failed to create a link (alias) in the
/usr/binfolder. You can fix it with a quick
$ sudo ln /usr/local/mysql-5.5.10-osx10.6-x86_64/bin/mysql /usr/bin/mysql
PS: This solution is based on the latest versions of the libraries available as of March 2011. You might need to change the versions in the commands or paths according to your machine settings.