Search code examples
ruby-on-railsrubyrvmcapistranorvm-capistrano

System rvm is not working on direct call


I am using CentOS. Here is my output:

# which rvm
/usr/local/rvm/bin/rvm
# rvm ruby-1.9.3-p392@gemset
# /usr/local/rvm/bin/rvm ruby-1.9.3-p392@gemset
RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.

As you can see if I am using just rvm everything is working. But capistrano using full path in commands like this

[46f28bd9] Command: cd /var/www/app/releases/20140718172057 && /usr/local/rvm/bin/rvm ruby-1.9.3-p392@gemset do bundle install --binstubs /var/www/app/shared/bin --path /var/www/app/shared/bundle --without development test --deployment --verbose

So it just fails and all gems being installed on default ruby instead of ruby-1.9.3-p392@gemset

Thanks for any suggestions.


Solution

  • My assumptions:

    • you are using Capistrano v3
    • have already included require 'capistrano/rvm' in your Capfile
    • when you cd into your project directory you have something like .ruby-version and .ruby-gemset setting up RVM for you.

    You might want to try something like this

    within fetch(:current_path) do
        with rails_env: fetch(:rails_env) do
            execute :bundle, "install"
        end
    end
    

    The way Tasks work in v3 is different: https://github.com/capistrano/capistrano#tasks

    tl;dr: execute(:bundle, :install) and execute('bundle install') don't behave identically!