16

是否可以在 shell 脚本中加载 rvm 。任何人都可以举一个例子。当我尝试 shell 脚本时。我正在使用ubuntu系统

#!/bin/bash
rvm use 1.9.3

它给了我错误

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.
4

3 回答 3

18

您可以通过执行以下操作在脚本中包含 rvm:

source ~/.rvm/scripts/rvm

那么 rvm 应该可用于您的脚本,

于 2013-11-13T12:46:31.620 回答
4

对于简单地对 RVM 管理的 Ruby(或系统 Ruby)执行命令,请执行以下操作:

rvm 1.9.3 exec camper_van

这假设rvm use 1.9.3并且gem install camper_van以前发生过,它提供了camper_van可执行文件

注意:RVM 预计已经加载 - 它通常用于在您的用户下启动的脚本(RVM is not a function, selecting rubies with 'rvm use ...'确认它已经存在)。

于 2014-06-05T08:10:07.237 回答
1
# Load RVM into a shell session *as a function*
# Loading RVM *as a function* is mandatory
# so that we can use 'rvm use <specific version>'
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
  # First try to load from a user install
  source "$HOME/.rvm/scripts/rvm"
  echo "using user install $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"
  echo "using root install /usr/local/rvm/scripts/rvm"
else
  echo "ERROR: An RVM installation was not found.\n"
fi
于 2013-11-13T12:47:25.780 回答