Installing Ruby on Rails on Mac OS X Lion
I spent lots of hours trying to get RoR to work on Lion. Perhaps this tutorial will help you save some time. Mac by default comes with Ruby 1.8.7 and is outdated. I had better luck getting Ruby 1.9.2 to work with Rails, which requires an upgrade process.
Before you attempt to upgrade Ruby, make sure you use Xcode 4.1, not version Xcode 3.x. Once I upgraded to Xcode 4.1 the whole installation process went much smoother. On another note, several sites recommend using the “sudo” commando to install packages (which escalates user permissions to root for a particular command) but this created conflicts, as the installed files were then assigned with root privileges. For example, when one installs Ruby with sudo privileges and Rails with regular user permissions conflicts arise. I know, a beginner mistake, but worth watching out for. I had more luck just sticking to regular permissions and not using sudo.
1) Install the latest version of XCode from the App Store (its free). Installing the latest version of Xcode 3.x from apple.com’s web site did not work for me. First, verify Xcode version:
$ xcodebuild -version
You should see the following message:
Xcode 4.1 Build version 4B110
2) Verify that Git was installed correctly with Xcode, its installed automatically with Xcode 4.1. Git is used to download and install packages from the GitHub repository. This ensures that you are always downloading the latest version of the package.
$ git --version (these are two dashes)
This command should return something such as:
git version 184.108.40.206
RVM (Version Manager)
3) Now you may install RVM. RVM allows you to manage multiple versions of Ruby on the same machine. RVM will be used later to point to the upgraded version of Ruby. It’s not a good idea to uninstall the version of Ruby (1.8.7) that comes with OS X.
$ bash < <( curl -s https://rvm.beginrescueend.com/install/rvm )
4) Add RVM to you profile path so that it loads on new terminal sessions.
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" ' >> ~/.bash_profile
If you like to open a terminal session and type bash, the above command can also be added to .bashrc, or use your favorite text editor to modify files. If you can’t see the files from within Finder, install Tinker Tool from the App Store (free) to expose hidden files. It’s simpler than using the vi editor.
Verify that your path has been updated:
$ echo $PATH
This should return something like:
…where (user) is your username.
By the way, during this step its a good idea to go ahead and add other paths that you may need, such as the ones above.
5) Close and re-open your terminal session. Type the following into your terminal:
$ type rvm | head -1
This should return:
rvm is a function
6) Now we are ready to install Ruby:
$ rvm install 1.9.2
This will download, compile and install Ruby 1.9.2 for you. If you run into any compilation errors during this step, make sure that Xcode 4.1 was installed correctly. You can see if gcc is available from the prompt just by typing:
$ gcc -v
Using built-in specs. Target: i686-apple-darwin11 Configured with:
/private/var/tmp/llvmgcc42/llvmgcc42-2335.15~25/src/configure –disable-checking –enable-werror
–prefix=/Developer/usr/llvm-gcc-4.2 –mandir=/share/man –enable-languages=c,objc,c++,obj-c++
–program-prefix=llvm- –program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ –with-slibdir=/usr/lib
–program-prefix=i686-apple-darwin11- –host=x86_64-apple-darwin11 –target=i686-apple-darwin11
–with-gxx-include-dir=/usr/include/c++/4.2.1 Thread model: posix gcc version 4.2.1 (Based on Apple
Inc. build 5658) (LLVM build 2335.15.00)
If that doesn’t come up then Xcode or the path is not set correctly. Make sure that /Developer/usr/bin:/Developer/ usr/libexec:/Developer/usr/sbin:/Developer/usr/local/bin are in your $PATH.
You can also add Ruby’s core documentation by typing:
$ rvm docs generate
7) Set Ruby 1.9.2 as the default and verify.
$ rvm use 1.9.2
$ Ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.4]
Ruby Gems (Package Manager)
8 ) Now verify that Ruby Gems is installed and that it’s above 1.6.2. Gems is Ruby’s package manager:
$ gem -v
If not, upgrade Ruby Gems with:
$ gem update --system
9) Now we need to install a database. For starters it’s better to begin with SQLite3: it’s already included with OS X. It’s simpler to verify that RoR is working with sqlite3, once that is done then one can upgrade to another database such as MySQL.
Verify SQLite3 version:
$ sqlite3 -version
This should return something similar to:
It’s important to verify that version 3.6.12 or higher is working on your machine. If not, you need to upgrade SQLite3:
$ mkdir ~/src
$ cd ~/src
$ curl http://www.sqlite.org/sqlite-3.7.5.tar.gz | tar xvz
$ cd sqlite-3.7.5
$ ./configure –prefix=/usr/local
$ make install
Verify SQLite3 version again. If it’s still on the old version, you may want to move /usr/local/bin/sqlite3 to /usr/bin/sqlite3.
10) Now install Ruby bindings for SQLite3:
$ gem install sqlite3
11) Next, we install Ruby’s web framework, Rails. You should have version 3.0.7 or higher installed:
$ gem install rails
Once that’s done, you can verify version by typing:
$ rails -v
This should return Rails 3.0.7 or higher.
12) The last steps make sure that RoR is working correctly. Go to your $HOME path and create a new directory, cd into it and create the skeletal application:
$ mkdir www
$ cd www
$ rails new myapp
$ cd myapp
This will create a bunch of files. Then, we start the rails server by typing:
$ rails server
Navigate to http://localhost:3000 which should display a “Welcome aboard” page.
I got tons of errors along the way, so if you are getting any maybe I can be of help, as I took lots of notes as I went along.
These sites helped me with the above steps: