Install Ruby, Rubygems, Ruby on Rails 3 & MySQL on Mac Snow Leopard

Install TextMate

  • Download & install TextMate
  • TextMate is used as the Ruby on Rails editor

Install XCode

  1. Download XCode from the Apple iOS dev center (Xcode is needed to build the Ruby from the source code)
  2. Install the application when the download is completed

Change the search path $PATH for the new location of Ruby, Rubygems & MySQL

  1. In finder, start the terminal application
    Go -> Applications -> Utilities -> Terminal
  2. Edit .profile
    mate ~/.profile
  3. Edit $PATH setting and save
    export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
  4. Change $PATH
    source ~/.profile

Install Ruby & Rubygems on Mac Snow Leopard (OS X 10.6)

  1. Create a directory for source code
    mkdir ~/src
    cd ~/src
  2. Download Ruby & Rubygems
    curl -O
    curl -O

Build Ruby on Mac Snow Leopard (OS X 10.6)

  1. Build Ruby
    tar xzvf ruby-1.8.7-p330.tar.gz
    cd ruby-1.8.7-p330
    ./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1
    sudo make install
    cd ..
  2. Close the terminal and open a new terminal. Verify the installation
    % ruby -v
    ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10.6.0]

Build Rubygems on Mac Snow Leopard (OS X 10.6)

  1. Build the Rubygems
    tar xzvf rubygems-1.5.2.tgz
    cd rubygems-1.5.2
    sudo /usr/local/bin/ruby setup.rb
    cd ..
  2. Close the terminal and open a new terminal. Verify the installation
    % gem -v

Install Ruby Debugger

Install the Ruby debugger and Ruby IDE Debugger

sudo gem install ruby-debug ruby-debug-ide

Install Rails on Mac Snow Leopard (OS X 10.6)

(Optional) To avoid an issue in installing rails, rebuild the rdoc first

Installing ri documentation for rails-3.0.4...
  File not found: lib
sudo gem install rdoc-data
sudo rdoc-data --install
sudo gem rdoc --all --overwrite

Install Rails

sudo gem install rails

Install NetBeans IDE 6.9 (Optional)

Alternatively, use NetBeans IDE 6.9 as RoR IDE

NetBeans 7.0 drops the RoR supports

Install MySQL on Mac Snow Leopard (OS X 10.6)

  1. Download MySQL community server from Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive
  2. After the download is completed
    1. Install mysql-5.5.9-osx10.6-x86_64.pkg
    2. Install MySQLStartupItem.pkg
  3. Double click MySQL.prefPane
  4. Start MySQL server in the panel

MySQL data file directory on Mac Snow Leopard


Secure MySQL server on Mac Snow Leopard

Open a terminal and secure MySQL user

% mysql -u root
mysql> use mysql
mysql> update user set password=PASSWORD("your_secret_password") where User='root';
mysql> delete from user where user='';
mysql> flush privileges;
mysql> exit

Drop the test database

% cd /usr/local/mysql/data
% sudo chmod og+w test
mysql> drop database test;

If the test directory is not open for write access by other, it cannot be removed

ERROR 1010 (HY000): Error dropping database (can't rmdir './test/', errno: 17)

Starting MySQL in Mac Snow Leopard (Mac OS X 10.6)

In the finder

System Preferences -> Other -> MySQL

Install Ruby gem MySQL2

sudo gem install mysql2 -- --with-mysql-dir=/usr/local/mysql

To overcome the following problem later in using the MySQL2 gem:

dlopen(/usr/local/lib/ruby/gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib
  Referenced from: /usr/local/lib/ruby/gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
  Reason: image not found - /usr/local/lib/ruby/gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle


sudo install_name_tool -change libmysqlclient.16.dylib \
/usr/local/mysql/lib/libmysqlclient.16.dylib \

Install Nokogiri XML on Mac

sudo port install libxml2 libxslt
sudo gem install nokogiri