Last Updated: February 25, 2016
· pravinsb

Guide to Installing Ruby, Ruby on Rails, Gems (Including mysql2 gem) on Mac OS 10.8

A long, hard and uneasy process for pretty much everyone on a new mac (as of today).

After about 10-15 different methods, a couple of complete re-installations of Mac OS, I have finally been able to pinpoint exactly what it takes to get Rails fully up and running on the Mac.

I will first break down all the issues that have caused me problems;

  1. The version of ruby that comes preinstalled on OS X 10.8 is outdated relative to the version of Rails that has to be installed. Hence installing Rails by itself is not ordinarily possible.

  2. In order to install rails (as will be shown below), an newer version of ruby must be installed. This causes problems when installing the gems (such as mysql2) as the location of the new ruby installation is not in the same location as the native ruby on OS X.

How to successfully install rails.

  1. Install Xcode from the Mac App Store (v4.6.3)
    a) Install command line tools: Xcode > Preferences > Downloads > Command Line Tools (Install)

  2. Download and install Railsinstaller from http://railsinstaller.org
    a) There will be an error the first time you try. This is normal, just restart your mac and try again.

  3. Download and Install MacPorts (https://distfiles.macports.org/MacPorts/MacPorts-2.1.3-10.8-MountainLion.pkg)

  4. Install MySQL (http://dev.mysql.com/downloads/)

  5. We can now install MySQL via MacPorts;
    Open Terminal and type;

sudo port install mysql55 mysql55-server

  1. We can now install mysql2 gem; In Terminal type;

sudo gem install mysql2 -- --with-mysql-config=/opt/local/lib/mysql55/bin/mysql_config

Now when you are accessing a ruby project through localhost, you are bound to get a mysql2 error when you hit 'About your application’s environment'.

A work around for this is with rake;
1. First install rake with (terminal);

sudo install rake

  1. Then move terminal to the directory of your ruby project (e.g. cd Sites/ruby_project) and enter in terminal;

rake db:create

This will solve the problem


3 Responses
Add your response


It's really not that hard. You just need Xcode Command Line Tools, RVM and rubygems. This is an excellent guide: http://www.moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/

over 1 year ago ·

@mrfoto – Yeh, it kinda gets hard come mysql2 gem's; That guide wont help you there

over 1 year ago ·

@pravinsb oh, didn't know that. I switched to postgres about a year ago and I love it.

over 1 year ago ·