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:

# You can also set GEM_PATH if needed