Development with Ruby on Rails can be a very productive and rewarding experience, but it has gained a reputation among the development community as being very painful to initially set up, especially if you are using Rails for the first time. A recent factory reset on OSX means coaxing Ruby 2 and Rails 4 to play nicely with each other once again, so I’ve decided to take some extra time and document each step along the way for reference. The result should be a working rails project.
Step 1: Homebrew
Go over to http://brew.sh and install and update homebrew.
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" && brew update
brew doctor, warns that I haven't accepted the XCode license and don't have XCode's Command Line Tools.
Step 2: XCode + Command Line Tools
Install the latest version of XCode from the App Store, fire it up and open Preferences. Under the Downloads tab, install Command Line Tools.
The default gcc compiler installed with XCode works, but some features are buggy, so let's grab Unix's standard command line tools, as well as a stand alone version of gcc-4.2.
$ brew tap homebrew/dupes && brew install apple-gcc42
brew doctor again reveals another warning that
/usr/bin occurs before
/usr/local/bin. To fix this error, add the following to
homebrew=/usr/local/bin:/usr/local/sbin export PATH=$homebrew:$PATH
brew doctor should reveal the system is "ready to brew".
Step 3: RVM (Ruby Version Manager)
Install RVM by running the following in terminal.
$ bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
Now add the following to your
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
Restarting the terminal, let's confirm RVM is actually there.
$ rvm -v rvm 1.21.8 () by Wayne E. Seguin <email@example.com>, Michal Papis <firstname.lastname@example.org> [https://rvm.io/]
Step 4: Ruby 2.0
At this point, we don't have Ruby 2 yet.
$ ruby -v ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]`
Let's upgrade to Ruby 2.
$ rvm install ruby-2.0.0-p247
Assuming all goes smoothly, running
rvm list should show Ruby 2.
$ rvm list rvm rubies =* ruby-2.0.0-p247 [ x86_64 ] # => - current # =* - current && default # * - default
Just to make sure…
$ ruby -v ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2]
Step 5: Rails 4.0
We don't yet have rails, so let's install it.
$ gem install rails --version 4.0.0
$ rails -v Rails 4.0.0
Step 6: Test Drive
Let's try setting up a brand new rails project.
$ rails new TestDrive && cd TestDrive
Make sure all gems are updated.
$ bundle update
Now start up your rails server.
$ rails server
localhost:3000 and you should see the "Welcome Aboard" page.