Apple has released their latest version of OS X, Lion, and with that, it’s time for me to update my install guides. I’ve been running the GM Seed of Lion since it was released and I’ve only encountered minor issues along with way with my current Rails development environment.
If you’ve read any of my guides before, you’ll notice that in this guide I’ve switched from using Passenger to using 37Signals’ Pow Rack server. I’ve found that when I upgraded from Snow Leopard, Passenger and Apache stopped serving requests. Both services didn’t have records of requests coming and there were no errors messages recorded. Since trying Pow, I’ve become a convert. It’s dead simple to install and get running.
With that being said, there are some caveats with Pow. First, it hijacks port 80. So if you’re developing other sites using PHP and Apache, there is some extra work for you ahead. Additionally, there is an open and outstanding issue where the server will go haywire and start monopolizing the CPU time. For me, these issues are minor (I just stop the process if it goes haywire – it’ll automatically restart itself) and I don’t develop in PHP.
Now that I’ve gotten that out of the way, let’s dive in shall we?
Whether you’re upgrading Snow Leopard or you have a fresh install of Lion ready to go, the first thing that you’ll need to do is install Xcode. It’s free and available at the Mac App Store.
One thing of note, unlike other applications from the Mac App Store, downloading it doesn’t mean installing it. Once downloaded you’ll have to run the Install Xcode application to get it installed.
Homebrew is a package manager that allows you to install all sorts of Open Source goodies on your Mac with a simple command. If you’re upgrading from Snow Leopard and you already had Homebrew installed, my experience has been that you don’t need to do anything different.
If you’re on a fresh install though, you can install Homebrew with the following command.
ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
Follow the instructions provided by Homebrew to complete the installation.
Pretty much every Rails hacker out there uses Git, so let’s grab that using Homebrew. Again, if you already had Git installed using Homebrew on Snow Leopard, you won’t need to do anything new here.
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. If you’ve upgraded, you won’t need to do anything new for zsh to continue working.
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 be running the change shell command.
chsh -s /bin/zsh
Although OS X comes with a version of Ruby, it’s somewhat out of date. We can work around the issue by installing RVM.
bash < <(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.
NOTE: When I upgraded, I was having an issue with Passenger, and I thought that my RVM install might be the culprit. So I removed RVM completely and simple re-installed it according the these instructions.
If you want to remove RVM complete run the following command:
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.
Optional Install: IConv Package
If you use the Nokogiri gem, you’ll probably need this package in order for it to compile.
rvm pkg install iconv
Installing Ruby Enterprise Edition
I’m not sure if the CC line is still necessary with the final release of Xcode 4, but with the GM seed and earlier versions of Lion, it wouldn’t work without it.
CC=/usr/bin/gcc-4.2 rvm install ree --enable-shared
If you installed the IConv package then the install command is:
CC=/usr/bin/gcc-4.2 rvm install ree --enable-shared --with-iconv-dir=$rvm_path/usr
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. Installing is simple:
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. If you’re upgrading from Snow Leopard, you don’t need to do anything different with your database servers.
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
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. 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 powder
The powder gem gives you a nice wrapper on some of the Pow commands.
Installing Pow is simple, just run this command in your terminal and enter your password when prompted.
curl get.pow.cx | sh
You can review the install script listed here, if you’re concerned about running command in your shell to automatically install things on your system:
All you need to do to get up and running is navigate to your project’s directory in the terminal and run the following command (assuming you installed the powder gem):
If the application is a Rails 2.3 application, it’ll prompt you to generate a base config.ru file. For my applications, I just followed the defaults.
Your web application should be available at http://mywebapplication.dev where “mywebapplication” is the name of the directory where your project lives. If there are underscores in the directory name, use hyphens in the URL.
This should be all that you need to get your projects running on the new version of OS X. Happy coding!