如何在shell脚本中使用rvm

时间:2013-11-13 12:40:00

标签: bash rvm

是否可以在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.

3 个答案:

答案 0 :(得分:16)

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

source ~/.rvm/scripts/rvm

然后你的脚本可以使用rvm,

答案 1 :(得分:2)

简单地对RVM托管的Ruby(或系统Ruby)执行命令:

rvm 1.9.3 exec camper_van

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

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

答案 2 :(得分:0)

# 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
相关问题