RVM won't work over SSH (as a function)

时光总嘲笑我的痴心妄想 提交于 2020-01-02 16:27:29

问题


I just installed RVM on a Debian 6 server, without having any problem in the beginning. However after everything is set up, I can't run RVM in the terminal. The message I get when I type rvm use is:

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.

I am logging in via SSH and can´t find a solution for this problem. In "rvm installation not working: "RVM is not a function"" they managed to solve the problem but not for SSH.


回答1:


run:

rvm get stable --auto-dotfiles

it will remove and re-add rvm lines from shell initialization files

for ssh connections to work you need to set your shell as bash(preferred) or zsh, you can check your current shell with:

getent passwd $USER | awk -F: '{print $NF}'

and if it is not bash/zsh change it with:

chsh $USER --shell `which bash`



回答2:


You need to source /etc/profile.d/rvm.sh first. Add the following line to your .bashrc (or type it at the prompt) :

source /etc/profile.d/rvm.sh

Alternatively, if you need a function, the following script works for me :

#!/bin/sh

#RVM stuff
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then

  # First try to load from a user install
  source "$HOME/.rvm/scripts/rvm"

elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then

  # Then try to load from a root install
  source "/usr/local/rvm/scripts/rvm"

else

  printf "ERROR: An RVM installation was not found.\n"

fi



回答3:


When SSH launches bash, bash doesn't source .bashrc, in default builds (there is a compile-time flag, SSH_SOURCE_BASHRC, that forces it to). Try using something like this in your SSH command line:

ssh user@host "bash -i"

See ssh command execution doesn't consider .bashrc | .bash_login | .ssh/rc?.



来源:https://stackoverflow.com/questions/20820549/rvm-wont-work-over-ssh-as-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!