I’ve been setting up a new MacBook Pro using rvm and gemsets to make it super easy to flick between different versions of rails and ruby (thanks Steve for this very useful post). I was aware that MySQL could be a problem if you get your architectures wrong so it’s important to download the 64 bit version of MySQL and that your ruby is also 64 bit. You can check that by using the following commands:

1
2
file `which ruby`
file `which mysql`

I was seeing x86_64 for both so everything was good.

I had already created a rails2.3.8 gemset using rvm and was ready to install the rails and mysql gems:

1
2
gem rails install -v 2.3.8
ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

However I was getting several errors. First off I couldn’t run the rails command because of this error:

1
uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)

And I couldn’t run my app because of this error in the passenger log:

1
uninitialized constant MysqlCompat::MysqlRes

Fixing rails

Lets start with the rails command error. Turns out theres an incompatibility between rails 2.3.8 and recent versions of rubygems. The suggested fix is to upgrade to rails 2.3.11.

1
2
gem uninstall rails
gem install rails -v 2.3.11

Obviously you’ll now need to go into your application and change your environment.rb to use 2.3.11…

1
2
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.11' unless defined? RAILS_GEM_VERSION

And tells rails to update your application…

1
rake rails:update

Once that’s done the first problem is fixed.

Fixing MySQL

I was still getting the MySQL error unfortunately. If you google the error you’ll get all sorts of explanations on how important getting the 64 bit architecture correct is when compiling the mysql gem. Well I’d done that!

I figured out the solution to my problem whilst checking out a ruby forum post on the issue. Some people on there were using symlinks to fix the issue but if you add your MySQL lib directory to your DYLD_LIBRARY_PATH then the problems go away. I’ve already been tinkering with my DYLD_LIBRARY_PATH as this environment variable is used for the Oracle instant client. So I simply opened up my .bash_profile and added the lib directory for MySQL:

1
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib

And now everything works. I’ve got no idea why it was needed and I’m not sure why a small minority of people need this fix whereas most don’t, but there it is.