Setting GEM_HOME on Phusion Passenger 3

I recently built a Ruby on Rails app, and I chose to install some Ruby gems locally (in my home directory) rather than system-wide. This worked from the console, when my GEM_HOME environment variable was read from .bashrc. However, when I wanted to deploy via Phusion Passenger, I was stumped as to how to get it to find GEM_HOME. I got errors such as the following:

Ruby (Rack) application could not be started
...
Could not find mysql2-0.2.6 in any of the sources (Bundler::GemNotFound)

Some pages suggested setting ENV['GEM_HOME'] in config/environment.rb, but this had no effect. Phusion Passenger calls Bundler.setup before loading the application. Instead, the fix is to put the necessary lines in config/setup_load_paths.rb. You’ll probably have to create this file:

ENV['GEM_HOME']='~/gems1.9.1'
# You can also set GEM_PATH if needed
#ENV['GEM_PATH']='~/gems1.9.1:/var/lib/gems/1.9.1'

Installing Catalyst on Debian, the easy way

A few notes I collected after searching online for information about installing Catalyst, the MVC Web framework for Perl. This approach uses pre-built Debian packages which install a lot quicker than compiling things yourself using CPAN — plus, this way you don’t have to tinker with the modules that somehow fail tests, which inevitably happens with such a large dependency base.

First, set up the unstable repository and pin it so that most packages don’t get installed from unstable — just the Perl ones.

/etc/apt/sources.list:

# the main Debian packages.
deb http://mirror.cc.columbia.edu/pub/linux/debian/debian/ lenny main contrib

# Unstable
deb http://http.us.debian.org/debian unstable main non-free contrib

/etc/apt/preferences:

Package: *
Pin: release a=stable
Pin-Priority: 700

Package: *
Pin: release a=lenny
Pin-Priority: 700

Package: *
Pin: release a=unstable
Pin-Priority: 600

Next, install a sampling of useful modules from Task::Kensho:

aptitude -t unstable install liblocal-lib-perl libtest-simple-perl \
    libtest-most-perl libtest-exception-perl libtest-pod-perl \
    libtest-pod-coverage-perl libtest-memory-cycle-perl \
    libdevel-cover-perl libmoose-perl libpoe-perl \
    libmodule-install-perl libperl-critic-perl libcarp-always-perl \
    libdatetime-perl

Install modules recommended by Catalyst docs:

aptitude -t unstable install sqlite3 libdbd-sqlite3-perl \
    libcatalyst-perl \
    libcatalyst-modules-perl libdbix-class-timestamp-perl \
    libdatetime-format-sqlite-perl libconfig-general-perl \
    libhtml-formfu-model-dbic-perl libterm-readline-perl-perl \
    libdbix-class-encodedcolumn-perl libperl6-junction-perl \
    libtest-pod-perl