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 over SSH:
local:~$ ssh leifg@server 'which ruby'
/usr/bin/ruby
I'm using Ubuntu 11.04.
How do I get SSH to use the same Ruby as it is on the system?
I already verified some prequisites:
- Ruby was already installed using
apt-get install ruby
. Does that make any difference? sshd_config
has the option "PermitUserEnvironment yes", and I restarted the daemon.
The .bashrc on the server contains these lines, but I see the same behavior when I remove them:
if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
. "$HOME/.rvm/scripts/rvm"
elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then
. "/usr/local/rvm/scripts/rvm"
fi
(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:From the
ssh
man page:This should mean that your
.bashrc
won't get sourced, so RVM doesn't get set up.Solution
This did the trick in the end:
Start bash as a login shell through SSH and then start the RVM installed Ruby via SSH's
-c
option.Actually there's totally another, more safe and lightweight option.
You add "PermitUserEnvironment yes" somewhere to your sshd_config in /etc/(open)ssh
Now you are allowed to specify user environment in /home/user/.ssh/environment. So what do you put there ?
Just something like :
so it looks like below :
Note: this also works work user-install RVM (not only for the system wide)
Now your are able to use ruby in ssh non interactive sessions :
Voila!
I had the same problem. I realized, that I accidentally installed RVM for multiple users, too. After deleting the directory /usr/local/rvm and edit ~/.bashrc like zoonmix suggested, the problem was solved.
I've just added at the top of ~/.bashrc (for git user) this string:
zoomix's is the best solution. But when you change with "ruby rvm use system" in terminal or what else you get an error : Warning! PATH is not properly set up, is not at first place.... To solve that put the snippet just before the return instead of at the top of the .bashrc file (Debian Jessie here)