RVM 无法通过 SSH 工作 [英] RVM is not working over SSH
问题描述
RVM 无法通过 SSH 运行.
RVM is not working over SSH.
在命令行:
leifg@host:~$ which ruby
/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby
通过 SSH 连接:
local:~$ ssh leifg@server 'which ruby'
/usr/bin/ruby
我使用的是 Ubuntu 11.04.
I'm using Ubuntu 11.04.
如何让 SSH 使用与系统上相同的 Ruby?
How do I get SSH to use the same Ruby as it is on the system?
我已经验证了一些先决条件:
I already verified some prequisites:
- Ruby 已经使用
apt-get install ruby
安装.这有什么区别吗? sshd_config
有选项PermitUserEnvironment yes",然后我重新启动了守护进程.
- 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.
服务器上的 .bashrc 包含这些行,但我在删除它们时看到相同的行为:
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
推荐答案
来自 ssh
手册页:
如果指定了命令,则在远程主机上执行而不是一个登录shell.
If command is specified, it is executed on the remote host instead of a login shell.
这应该意味着您的 .bashrc
不会获得源代码,因此不会设置 RVM.
This should mean that your .bashrc
won't get sourced, so RVM doesn't get set up.
解决方案
这最终成功了:
ssh <host> bash --login -c <command>
通过 SSH 将 bash 作为登录 shell 启动,然后通过 SSH 的 -c
选项启动 RVM 安装的 Ruby.
Start bash as a login shell through SSH and then start the RVM installed Ruby via SSH's -c
option.
这篇关于RVM 无法通过 SSH 工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!