Recommend
If you like my work with RVM, please recommend me *with a comment as to why you recommend me* on
Working With Rails – Thank You!
IRC
I am 'wayneeseguin' in #rvm on irc.freenode.net
If I do not respond right away, leave a message and I'll respond or leave you a memo when I am around.
Sponsors
$ rvm help # Documentation Index

Using RVM rubies with Passenger

RVM will allow you to use any of it's MRI/YARV rubies with passenger very easily.

Passenger

Passenger is essentially 'mod_ruby' for both Nginx and Apache. You may select *exactly one* Ruby to run all of your Passenger Ruby applications with. If you need to run more than one Ruby interpreter then you should choose the most common one as Passenger Ruby. You then use proxy pass to external application servers such as Passenger Standalone, Unicorn, Thin, Mongrel, Mongrel2, etc... in order to accomplish running different applications under different rubies. For a full explanation of this (with pretty pictures!) see the post on Phusion's Blog

Passenger *3*

Installing Nginx/Apache with Passenger

First of all there's passenger-install-apache2-module and passenger-install-nginx-module. At the end of the installation it outputs a PassengerRuby configuration snippet for the web server. Its value is set to the RVM Ruby wrapper script that corresponds with the RVM Ruby and RVM gemset that was used to run the installer. This should be all you need for configuration of Passenger 3!

If it's not, here's what you might have to do, almost all of this stolen from Darcy's Blog Post

In your .rvmrc do:

if [[ -s "/Users/sutto/.rvm/environments/ree-1.8.7-2010.02@my-app-name" ]] ; then
  . "/Users/sutto/.rvm/environments/ree-1.8.7-2010.02@my-app-name"
else
  rvm --create use  "ree-1.8.7-2010.02@my-app-name"
fi

Then in the rails project, add a new file config/setup_load_paths.rb and add

if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
  begin
    rvm_path     = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
    rvm_lib_path = File.join(rvm_path, 'lib')
    $LOAD_PATH.unshift rvm_lib_path
    require 'rvm'
    RVM.use_from_path! File.dirname(File.dirname(__FILE__))
  rescue LoadError
    # RVM is unavailable at this point.
    raise "RVM ruby lib is currently unavailable."
  end
end

# Pick the lines for your version of Bundler
# If you're not using Bundler at all, remove all of them

# Require Bundler 1.0 
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
require 'bundler/setup'

# Require Bundler 0/9
# if File.exist?(".bundle/environment.rb")
#   require '.bundle/environment'
# else
#   require 'rubygems'
#   require 'bundler'
#   Bundler.setup
# end

Please note that for Passenger 3 you now use the ruby wrapper script directly with no need to use the passenger_ruby wrapper.

Starting Passenger Standalone

Then there's Passenger Standalone, i.e. 'passenger start'. Passenger Standalone uses Nginx internally, and it writes a passenger_ruby directive to the Nginx configuration file. This directive points to the RVM Ruby wrapper script that corresponds with the RVM Ruby and RVM gemset that was used to run the 'passenger start' command.

Bundler Gotcha

When using Bundler in your project, Passenger will try to be smart and only add to your $LOAD_PATH the gems listed in your Gemfile. This can lead to "unable to load" errors for your unlisted gems (this should only happen during development). You can check your run-time load path by adding

f = File.open('/tmp/load_path', 'w')
f.write($:)
f.close

to your app's main file (before the "require" calls). You won't be able to load any gems that are not in that load path.

Passenger *2* with RVM

Select a Passenger Ruby and Generate Wrapper Scripts

Run RVM using your desired Ruby interpreter, and pass the '--passenger' option. This will generate wrapper scripts in RVM's bin directory (see Notes below). These wrapper scripts ensure environment variables such as GEM_HOME and GEM_PATH are set correctly for applications run by passenger. E.g:

rvm ree --passenger

Alternatively, you can use the rvm wrapper command directly:

rvm wrapper ree@ninjas passenger

Install Passenger

rvm ree
gem install passenger
rvmsudo passenger-install-nginx-module

Or if you are forced to use the tomahawk,

rvmsudo passenger-install-apache2-module

Configure the Web Server

For Nginx users, replace the passenger_ruby line with:

passenger_ruby /home/wayne/.rvm/bin/passenger_ruby;

For apache users, use:

PassengerRuby /home/wayne/.rvm/bin/passenger_ruby

Please note that if you installed rvm as root / are using a system wide ruby, instead of using /home/wayne/.rvm/bin/passenger_ruby as in the above examples, you'll instead need to use /usr/local/rvm/bin/passenger_ruby.

Notes

Troubleshooting

FAQ

Community Resources

RVM Documentation Index