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:
Create a new gemset
Edit the .rvmrc file and add the gemset to be used, aswell as the ruby version needed for it
Trust the .rvmrc file
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:
Paste the following into the newly create file:
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.