Using RVM rubies with Capistrano
You currently have three options:
- If your rvm version on the server and locally are recent enough, use the new built in integration.
- Enable .ssh environment variables using the PermitUserEnvironment option in your ssh configuration file
- Use the capistrano :default_environment setting
Integration via the rvm capistrano plugin
If your rvm installs on both sides are recent enough (>= 1.0.1), rvm has a new plugin available that takes advantage of a different approach. In the new option, you can do the following (adjust to your personal setup):
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
require "rvm/capistrano" # Load RVM's capistrano plugin.
set :rvm_ruby_string, 'ree@rails3' # Or whatever env you want it to run in.
This option is preferred as it reduces configuration and does not contain hardcoded paths. Please note that RVM will not be automatically loaded as a shell function but it will be available as a binary in PATH (for differences between the two versions, please see our scripting page for further clarification).
Please note that this defaults to using a system wide / root install, if you wish to instead set it to use an rvm install in the deploying users home directory, add the following to your Capfile / deploy.rb:
set :rvm_type, :user # Copy the exact line. I really mean :user here
Integration via :default_environment
For the second option add the following line in your deploy.rb file, adjusting to your particular rvm ruby of course,
set :default_environment, {
'PATH' => "/path/to/.rvm/gems/ree/1.8.7/bin:/path/to/.rvm/bin:/path/to/.rvm/ree-1.8.7-2009.10/bin:$PATH",
'RUBY_VERSION' => 'ruby 1.8.7',
'GEM_HOME' => '/path/to/.rvm/gems/ree-1.8.7-2010.01',
'GEM_PATH' => '/path/to/.rvm/gems/ree-1.8.7-2010.01',
'BUNDLE_PATH' => '/path/to/.rvm/gems/ree-1.8.7-2010.01' # If you are using bundler.
}
To get the accurate locations have a look at cat ~/.rvm/config/default
Also, in order to have capistrano automatically trust project rvmrc files on deployments, you can do the following. In your 'config/deploy.rb' you can add:
namespace :rvm do
task :trust_rvmrc do
run \"rvm rvmrc trust \#\{release_path\}\"
end
end
And then use capistrano's hooks capabilities, by adding an 'after' hook like the following:
after "deploy", "rvm:trust_rvmrc"
to launch it.