Found Elsewhere…


Sandboxing Rails v2

Published by Robert Bousquet on 2010-07-05 00:48:00 UTC

(This article is a work in progress. Still have a few things to test before I can fully recommend this version.)

It’s been a while since I’ve drastically changed the way that I manage my Rails stack. Going back to 2005, MacPorts seemed to be the way to go. Along the way, due to dependencies and the differing pace of each package there were times when my recipe didn’t work or needed to be updated with specific portfile hacks or versions. A lot has changed and in the last 5 years of Rails development and with Rails 3 right around the corner I figure it’s time to give this stack another approach.

One of the features of MacPorts is that it installs everything into /opt to isolate it from the Apple-provided development packages in /usr/bin. This is a double-edged sword that does provide isolation, but at the cost of straying from the Linux-established recommendation to put user-installed files into /usr/local/bin. This ends up requiring you to re-install many of the packages and libraries that Apple already provides and can cause some headache when the dependencies and packages don’t find what they’re looking for in your /usr or /usr/local areas.

A recent development in the Rails world is Homebrew, which helps you to manage these core development packages by automating the compilation process for each package from source. It adheres to the /usr/local namespace and at the same time, provides isolation of the packages through the clever use of symlinks to it’s own /usr/local/Cellar folder where the executables actually live. It does not provide any packages that Apple already provides (unless there’s some major flaw in Apple’s version) so that you don’t have to choose between Apple-provided Subversion or your own, for instance.

In any case, this is what I’m thinking will be my next stack recipe for Rails 3 (while at the same time supporting dozens of Rails 2 and a few Rails 1 apps from the past):

1. Install OSX Snow Leopard + X11 and XCode 2.3.2 (with optional iPhone 4SDK)
2. Install Homebrew (current method described on

$ ruby -e “$(curl -fsS”

3. Install the brew-based packages we need:

$ brew install wget
$ brew install git
$ brew install mysql
$ brew install ghostscript
$ brew install imagemagick

4. Install rvm to handle multiple ruby versions

$ sudo gem install rvm
$ rvm-install

Then install each of the Ruby versions you need. Since I have so many apps in the past, I’m just going to install all of the recent versions. If you are just getting started and only want to run Rails 3, then just do the last 1.9.2 version.

$ rvm install 1.8.6 —default
$ rvm install 1.8.7
$ rvm install 1.9.1
$ rvm install 1.9.2

5. Inside of each Ruby version, you’re going to need to install all of your gems. It’s probably good to make a large list of them first, then run them in bulk.

$ rvm use 1.8.6
$ gem install rails

$ rvm use 1.9.2
$ gem install rails —pre