35

Does anybody know how I can tell capistrano to use my default rvm version of ruby for on the server I am pushing to. It insists on using the system version.

Is it even possible?

Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
  • 2
    I am not putting this in an answer because I am hoping someone else *really* knows how to do this, but it seems from my quick research you will need to alter the `PATH` variable to include the path to your RVM ruby before the default one: http://kete.net.nz/documentation/topics/show/240-configuring-sudo-path-in-capistrano-deployments – Doug Neiner Dec 30 '09 at 07:06

6 Answers6

37

You have two options:

  1. Enable .ssh environment variables using the PermitUserEnvironment option in your ssh configuration file
  2. Use the capistrano :default_environment setting

For the second option, simply add the following line in your deploy.rb file

set :default_environment, { 
  'PATH' => "/path/to/.rvm/ree-1.8.7-2009.10/bin:/path/to/.rvm/gems/ree/1.8.7/bin:/path/to/.rvm/bin:$PATH",
  'RUBY_VERSION' => 'ruby 1.8.7',
  'GEM_HOME' => '/path/to/.rvm/gems/ree/1.8.7',
  'GEM_PATH' => '/path/to/.rvm/gems/ree/1.8.7' 
}

To get the accurate locations have a look at cat ~/.rvm/default

Chris Salzberg
  • 27,099
  • 4
  • 75
  • 82
Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
  • I think the first PATH setting should be `path/to/.rvm/rubies/ree-1.8.7` My RVM installation uses `rubies` anyway as the directory that ruby is actually isntalled – brad May 21 '10 at 15:14
  • 1
    thank you, I found this after way too much time beating my head against the wall. – Paul Dec 20 '11 at 05:57
  • This will also work for non-rvm server installations that use a non-standard location for ruby (like REE installed in `/opt` for example). To get the right paths in this case, use `which ruby` and `gem environment`. You may not need to set `GEM_HOME`. – foz Jan 23 '12 at 00:49
23

If your rvm version is recent on both development and production machines add this to your deploy.rb:

set :rvm_ruby_string, '1.9.2@yourapp' # you probably have this already
set :rvm_type, :user # this is the money config, it defaults to :system
  • 3
    For this why does it matter if rvm is on my dev machine? Shouldn't it only matter if it is on the production machien? – Hortitude Feb 10 '12 at 04:18
10

The rvm-capistrano gem is the best way to go.

Link to the official detailed usage of that gem. From that I am guessing this will get the local version of Ruby:

set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"") # Read from local system
CharlesB
  • 86,532
  • 28
  • 194
  • 218
KendallB
  • 4,799
  • 4
  • 19
  • 21
7

See http://rvm.io/integration/capistrano/. "Integration via the rvm capistrano plugin" looks like a winner.

And http://rvm.io/deployment/

mpapis
  • 52,729
  • 14
  • 121
  • 158
Matt Scilipoti
  • 1,091
  • 2
  • 11
  • 15
1

I found out the easiest way is to add the version you want. Just add

ruby-2.5.0

string (or the version you want) into .ruby-version in the root folder. No need to configure deploy.rb or some rather hacky solutions.

muhammadn
  • 330
  • 3
  • 18
0

For rbenv, don't forget to change set :rbenv_ruby, "3.0.0" in Capfile :)

Dorian
  • 7,749
  • 4
  • 38
  • 57