1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Installing Ruby on Rails on OS X

By

Installing Ruby on Rails on OS X

Installing Ruby on Rails on Apple OS X should be a no-brainer. Apple has decided that Ruby is a first class language and that it's going to support Ruby and Ruby on Rails by including it in the base distribution. That's a good gesture, but in the end it's not all that useful. Ruby and Ruby on Rails are moving targets, you probably don't want the version Apple included when they released the latest version of Apple OS X, you probably want the newest version. And the same thing goes for Ruby. So while Apple's support is not meaningless, it is a bit useless for Ruby on Rails developers.

So first off, you're going to need to install Ruby. As mentioned above, Apple does include Ruby with OS X, but OS X Lion (OS X version 10.7.3, the current version as of this article) comes with Ruby 1.8.7. Who uses 1.8.7 anymore? In fact, Ruby on Rails 4 won't even support 1.8.7, so it's best to upgrade to 1.9.3 ASAP. There was an issue when the 1.9.x tree first came out of not all gems supporting 1.9.x, but those days are gone. All the commonly used gems support 1.9.x now. Don't let Apple manage your Ruby version, do it yourself. And the easiest (or at least the most repeatable and reliable) way of doing this is to use RVM, the Ruby Version Manager.

To compile Ruby you'll need Xcode, Apple's IDE, GCC, clang, libraries, etc all rolled into one. The most modern way to install this is on the new (as of OS X Lion) OS X App Store. It's free, you can install it in one click, go here to install it. Once you do that you'll have a typical GCC environment at your disposal, including GCC, make, autotools, etc.

Next, download and install RVM. This is a rather painless process, detailed on their web site. RVM is written as a set of shell scripts, so there's no compilation needed here. The methods for installing RVM change from time to time (though they seem to have stabilized lately), but currently the following command will install RVM.


$ curl -L get.rvm.io | bash -s stable

Once you have that out of the way, you'll need to install Homebrew to get easy access to Git, among other things. Homebrew is something along the lines of MacPorts or Fink, but much more flexible, easy to use and it just happens to use Ruby. It's billed as the "missing package manager for OS X," and it really lives up to its name. With previous systems such as MacPorts, it was very difficult to uninstall software, installing something just scattered files everywhere. Homebrew tries to fix this by keeping things much more organized and using symbolic links to "install" them into the system. Its installation is a bit similar to RVM's.


/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

You're almost there. Time to install the Git revision control software, which is dead easy with Homebrew. While Git won't be necessary for any steps here, you really should be using it with all Ruby on Rails applications, even if you're just developing them alone. You'll also need it to interact with Github, the most active Ruby and Ruby on Rails code sharing site at the moment.


$ brew install git

All of the libraries you'll need for Ruby and Rails (including SQLite3) should be installed along with OS X, so you're finally ready to install Ruby and Ruby on Rails. This is done with RVM for Ruby, and then a Rubygems command for Ruby on Rails.


$ rvm install 1.9.3
$ rvm use 1.9.3
$ gem install rails

You should be done now. You have Ruby, Ruby on Rails, SQLite, a full development environment should you need to install any newer versions of Ruby, or any gems with native extensions, you have Git and Homebrew should you need any more tools. This is about as complete as you can expect to be. It's not quite as easy as installing Ruby on Rails on Windows with the Rails Installers, but you get there in the end. Maybe in the future they'll release a Rails installer complete with DevKit for OS X, that will eliminate the need for Xcode and Homebrew, but right now this is what you have to work with.

  1. About.com
  2. Technology
  3. Ruby
  4. Ruby on Rails
  5. Ruby on Rails 3 Tutorials
  6. Installing Ruby on Rails on OS X

©2014 About.com. All rights reserved.