Rails Ultimate Install Guide on OS X Snow Leopard (using RVM, Homebrew, and Passenger)
I’ve written numerous guides over the years on installing Ruby on Rails on Snow Leopard. This is an amalgamation of that knowledge and experience. It’s also my last guide that I’ll write for Snow Leopard now that OS X Lion is on the horizon.
Let’s jump right in.
Installing XCode
This whole process breaks down if you don’t install XCode, so we’ll do that now. You can use the XCode that came with your install DVD or download it online.
Installing Homebrew
I used to use MacPorts as my package manager but I’ve recently switched over to using Homebrew. Installing Homebrew is easy since OS X comes with a version of Ruby pre-installed.
ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
Follow the instructions provided by Homebrew to complete the installation.
Installing Git
Pretty much every Rails hacker out there uses Git, so let’s grab that using Homebrew.
brew install git
Optional Install: wget and oh-my-zsh
The following is completely optional, but I recommend them. By default, OS X uses the bash shell when interacting with the terminal, but that’s not the only shell available. I prefer zsh myself and for my install process, I use Robby Russell’s oh-my-zsh. It’s easiest to install oh-my-zsh with wget, so we’ll install that first.
brew install wget
Once wget is installed, installing oh-my-zsh is easy.
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
Follow any prompt by the install script to complete installation. Closing and re-opening your terminal should launch zsh from now on. To check run this command:
ps -p $$
You should see zsh instead of bash. If you don’t you can switch your shell manually by running the change shell command.
chsh -s /bin/zsh
Installing RVM
Although OS X comes with a version of Ruby, it’s sorely out of date. We can work around this issue by installing RVM.
If you’ve opted not to install oh-my-zsh, then replace zsh with bash in the command below.
zsh < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Follow any prompts from the RVM install process to complete the installation. One of the final install steps for RVM is automatically loading into a shell session. You should follow the latest install step but for my copy and paste purposes those are:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
Close the shell and restart it in order to have RVM loaded.
Installing a Ruby Interpreter
Since I have Rails applications that I work on that still haven’t been migrated to Ruby 1.9.2, I use Ruby Enterprise Edition as my baseline Ruby install.
Install the Readline package
I’ve always installed the Readline package with my Ruby REE install, so let’s do that now.
rvm pkg install readline
Optional Install: IConv Package
One of our projects is using the spreadsheet Ruby gem and that requires the IConv RVM package.
rvm pkg install iconv
Installing Ruby Enterprise Edition
rvm install ree --enable-shared --with-readline-dir=$HOME/.rvm/usr --patch readline-fix --with-iconv-dir=$rvm_path/usr
Obviously, you’ll want to discard the IConv argument if you didn’t install the RVM package. Installing a Ruby interpreter will take a while as it has to download and compile it.
As I said before, I use REE as my base Ruby install so when it’s installed, I’ll set it as my default.
rvm --default use ree
Optional Install: Ruby 1.9.2
Although my base Ruby install is REE, I usually use Ruby 1.9.2 for any new Rails 3 applications.
rvm install 1.9.2
Installing Database Servers
Although SQLite works for most smaller projects, MySQL and PostgreSQL are usually needed for larger projects. Installing them is easy with Homebrew.
Installing MySQL
brew install mysql
Make sure that you follow the instructions at the end to complete the installation and setup. You can review the post install instructions at any time by using the Homebrew info command.
brew info mysql
Installing PostgreSQL
brew install postgres
Again, make sure that you follow the instructions at the end to complete the installation and setup. As with MySQL, you can review the post install instructions at any time by using the Homebrew info command.
brew info postgres
Installing Base Gems
One of the cool things about RVM is that you can create gemsets. These allow you to compartmentalize your Ruby gem installs. By default, RVM creates one global gemset that others will inherit from. In this gemset, I usually apply some base gems that I want across all projects. I also install the Passenger gem at this stage. A full treatise on gemsets is beyond the scope of this guide so I urge you to read the RVM documentation for more information.
gem install bundler
gem install capistrano
gem install capistrano-ext
gem install git_remote_branch
gem install open_gem
gem install heroku
gem install passenger
Installing Passenger Apache Module
Before we install Passenger, we have to update the RVM wrapper scripts. I’m not sure why installing a new instance from the Internet doesn’t include everything we need, but Passenger usually complains at the end of the install process if you haven’t done it.
rvm get head && rvm reload && rvm repair all
Once that’s completed, finish setting up the module.
passenger-install-apache2-module
At the end of the install process, you’ll need to let Apache know that it needs to load the module. I do this by creating a passenger.conf and pasting the code lines from the install instructions.
sudo touch /private/etc/apache2/other/passenger.conf
You’ll need to use sudo because that directory is owned by root and you won’t be able to modify it with your account. Open the newly created file with your favorite text editor and paste in the code at the end of the install instructions. Your config file should look something similar to this:
LoadModule passenger_module /Users/carlos/.rvm/gems/ree-1.8.7-2010.02@global/gems/passenger-3.0.1/ext/apache2/mod_passenger.so
PassengerRoot /Users/carlos/.rvm/gems/ree-1.8.7-2010.02@global/gems/passenger-3.0.1
PassengerRuby /Users/carlos/.rvm/wrappers/ree-1.8.7-2010.02@global/ruby
# Set the default environment to development
RailsEnv development
# Which directory do you want Apache to be able to look into for projects?
<Directory "/Users/carlos/work">
Order allow,deny
Allow from all
Options -MultiViews
</Directory>
Installing RubyCocoa and the Passenger Preference Pane
Although it’s quite old, I still use the Passenger Preference Pane for managing Rails and Rack apps. The current version requires RubyCocoa so we’ll need to install that first.
Installing RubyCocoa
cd ~/
wget http://sourceforge.net/projects/rubycocoa/files/RubyCocoa/1.0.0/RubyCocoa-1.0.0.tar.gz/download
tar xzf RubyCocoa-1.0.0.tar.gz && rm RubyCocoa-1.0.0.tar.gz && cd RubyCocoa-1.0.0
ruby install.rb config --build-universal=yes
ruby install.rb setup
# have to sudo to install this because the installer wants to copy example stuff out of the /System dir
sudo ruby install.rb install
cd ~/
rm -rf ~/RubyCocoa-1.0.0
Once RubyCocoa has been installed, you can download the Passenger Preference Pane.
Optional Install: Pow!!
Recently, 37Signals released a zero-configuration Rack server for Mac OS X called Pow!!. This removes the need for Passenger, RubyCocoa and the Passenger Preference Pane. This project is still very young as of this writing and I haven’t had a chance to try it myself, but if you’re feeling up it, to the installation instructions and the documentation are quite good.