Installing Ruby on Rails 2.3.3 and MySQL on Mac OS X 10.6

At my new job, I got a very nice new MacBook Pro 2.66 GHz Intel Core i7 with Snow Leopard (OS X 10.6.3) preinstalled. In order to support a legacy app, I needed to install Rails 2.3.3. Needless to say, it was problematic…

OS X

A standard Apple Menu → Software Update upgraded the OS to 10.6.6.

Ruby and Rubygems

These were both preinstalled as confirmed by the following: $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] $ gem -v 1.3.5

MySQL

I downloaded mysql-5.5.8-osx10.6-x86_64.dmg from here and installed it. There were two problems. First, on login, I saw a dialog box as follows:

The solution was here: $ sudo chown -R root:wheel /Library/StartupItems/MySQLCOM

Second, starting MySQL from the system preferences pane had no effect. The Console revealed the following error:

2/2/11 8:49:49 AM [0x0-0x16016].com.apple.systempreferences[179] /usr/local/mysql/support-files/mysql.server: line 256: my_print_defaults: command not found

The solution was here:

  1. Edit /usr/local/mysql/support-files/mysql.server
  2. Search for "Set some defaults"
  3. about 4 lines down, replace the line basedir=. with basedir=/usr/local/mysql
  4. Then search for "Set pid file if not given". About 3 lines down, replace the line mysqld_pid_file_path=$datadir/`hostname`.pid with mysqld_pid_file_path=$datadir/`/bin/hostname`.pid
  5. Now the prefPane will work.

Rails

This was easy: $ sudo gem install rails --version 2.3.3 Successfully installed rails-2.3.3 1 gem installed Installing ri documentation for rails-2.3.3... Installing RDoc documentation for rails-2.3.3...

MySQL Gem

This was the tough part.

First, I had to download and install XCode to get the required header files. The latest version was xcode_3.2.5_and_ios_sdk_4.2_final.dmg which requires OS X 10.6.4. It’s faster if you can install it off your system DVD.

After that, the following command worked for me:

export ARCHFLAGS="-arch x86_64" ; sudo gem install --no-rdoc --no-ri mysql -v 2.7 -- --with-mysql-dir=/usr/local --with-mysql-config=/usr/local/mysql/bin/mysql_config

The ARCHFLAGS reflected the 64-bit Ruby and MySQL I am running. The –no-rdoc and –no-ri served to suppress several warnings. The 2.7 version was (apparently) required for the 2.3.3 version of rails.

IMPORTANT

This was still resulting in errors, but then I found this post. The following command needed to go into my ~/.profile file to run every time I fired up a terminal:

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

Now, I am able to run rake tasks and script/server.

Tags: Technical

Updated at: 2 February 2011 12:02 PM

NO COMMENTS ALLOWED