RVM is not working over SSH.
At the command-line:
leifg@host:~$ which ruby
/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby
Connected
Make sure that on the server you have done something like rvm --default 1.9.2
to set RVM's Ruby to be the default. Otherwise, it will always use the default system Ruby.
“rvm” has two invocation bugs: the default installation drops the file /etc/profile.d/rvm.sh
and believes any bash trick is now globally available. – This assumption is wrong.
Files in /etc/profile.d/
are “sourced” on login, but maybe not from bash, maybe not even from a shell. So the cd
hook it installs is not there after the shell which runs these files exits. Actually, because of the buggy way “rvm” installs this hook, it is already gone once you run naked bash
in a login-shell!
I don’t know if “rvm” supports an explicit invocation for virtual environments, without relying on cd
ing into some directory (that I consider the second bug).
There is one sane workaround:
Make your shell source /etc/profile.d/rvm.sh
from e.g. ~/.bashrc
. .bashrc
is executed from any non-login bash, and login-bash is usually setup to source .bashrc
from those login-shell files like ~/.profile
For your ssh problem: should a proper ssh-shell not be login-shell anyway?
(if using Capistrano) Don't use rvm1/capistrano3 or rvm/capistrano; don't set :pty.
Change ~/.rvmrc
for the runner user, on the server, to this — note that it has to come before the line where it kills itself when not running interactively:
# get rvm for non-interactive shells (eg capistrano) too
source /etc/profile.d/rvm.sh
export BASH_ENV=$HOME/.bashrc
export rvm_is_not_a_shell_function=0
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
Mentioned solutions work certainly fine, but mine was to run
source /usr/local/rvm/environments/<ruby version>@<gemset version>
at the start of the remote ssh call. Something like:
ssh -l <remote username> <server ip> "source /usr/local/rvm/environments/<ruby version>@<gemset version> ; <rest of the remote script>"