Multiple RVM gemset with Passenger

RVM gemset I seem to never remember the steps for this procedure (and I’ve needed it a few times already), so I figured I would just write it down here for future reference.

We need to give instructions to passenger to load up the right gemset in our application’s directory.
.rvmrc file

Create an .rvmrc file in the web application’s root directory:

> touch .rvmrc

Create a new gemset

> rvm gemset create example

Edit the .rvmrc file and add the gemset to be used, aswell as the ruby version needed for it

> echo “rvm use 1.9.2@example” >> .rvmrc

Trust the .rvmrc file

> rvm rvmrc trust

Passenger

Passenger doesn’t know about our project-specific gems whereabouts so we need to give it an access path to locate them. In order to do this, we create a new file called setup_load_paths.rb in the config folder of the application like so:

> touch config/setup_load_paths.rb

Paste the following into the newly create file:

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
raise “RVM ruby lib is currently unavailable.”
end
end

Restart the server and we’re done.

> touch tmp/restart.txt