Installing Ruby On Rails On A Mac

Filed in Product & Development by Bret McGowen | March 13, 2013 11:15 am

Installing Rails can be one of the trickiest things to overcome for a newbie to Ruby and Ruby on Rails[1]. Being an open source project with lots of dependencies is a great strength for Rails and allows it to innovate quickly, but it has the unfortunate side effect of making a prospective developer jump through a lot of hoops, particularly for someone new to programming or new to the Unix/Linux world.


Windows users are in luck as there is a great, no hassle installer available at[2]. This is about as easy as it gets for installing Rails; unfortunately, my experience on a Windows laptop (even one with an SSD) is that Rails development can be painfully slow due the large amount of file I/O that Rails development entails.


This is bound to change, and I had to rewrite some of these instructions over the course of installing Ruby on Rails on a couple of different Macs with different versions of OS X and XCode. But here is what worked for me on Mountain Lion (OS X 10.8) and XCode 4.5.2. There are a couple of terms and concepts to be familiar with.

Installing Rails

Install XCode:

Please note that the next several installation commands should be run in the Terminal application.

Install Homebrew and apple-gcc42
This installs the Homebrew package manager and a GCC compiler

$ ruby -e "$(curl -fsSkL"
 $ brew tap homebrew/dupes
 $ brew install apple-gcc42
 $ sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2

Install RVM:
In the OS X Terminal, issue the following commands:

$ \curl -L | bash -s stable --ruby

Note: run the source command outputted from the above command

$ rvm install 1.9.3
$ rvm use 1.9.3
$ rvm --default 1.9.3

The above commands install RVM, install ruby version 1.9.3, tell RVM to use the 1.9.3 version for the rest of the stuff you’ll install and set 1.9.3 to be default going forward.

Install XQuartz

NOTE: This step is optional and is only necessary if you plan to do image manipulation using ImageMagick.

Apple no longer ships an X Windowing system starting with Mountain Lion, so you’ll probably need to install the open sourced version of this available at[5]

Install Rails

$ gem install rails

Rails should now be installed. To create a test app, run

$ rails new my_app_name

If you get an error about OpenSSL support, you may need to update RVM. See the instructions at[6]

Optional: MySQL
MySQL is a popular open source database that you may want to install locally to make sure that it behaves the same as your production instance of MySQL (if that’s what you’re running). Rails abstracts a lot of the different database differences to your app, but you still may want to actually run MySQL just to have the added confidence that there aren’t any subtle quirks/differences.

$ brew install mysql

 $ unset TMPDIR

 $ mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

 $ mysql.server start

 $ /usr/local/opt/mysql/bin/mysqladmin -u root password '[[[YOUR_ROOT_PASSWORD_HERE]]'

If you want to have MySQL start automatically when your Mac logs in, you can set it up like this:

$ mkdir -p ~/Library/LaunchAgents
$ cp /usr/local/Cellar/mysql/5.5.27/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Optional: ImageMagick

$ brew uninstall imagemagick
 $ brew install --fresh imagemagick

Done! I had to try a lot of combinations to get it working on my laptop and my app; hopefully this helps as most of the online resources I found were out of date for Mountain Lion or the newest version of XCode.

There are also more detailed instructions for the Mac, as well as Linux installation instructions available at[7]

Happy coding!

  1. a newbie to Ruby and Ruby on Rails:
  3. Homebrew:
  4. RVM:

Source URL: