如何在shell脚本中使用rvm

use*_*342 12 bash rvm

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

#!/bin/bash
rvm use 1.9.3
Run Code Online (Sandbox Code Playgroud)

它给了我错误

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.
Run Code Online (Sandbox Code Playgroud)

jbr*_*jbr 17

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

source ~/.rvm/scripts/rvm
Run Code Online (Sandbox Code Playgroud)

然后rvm应该可用于你的脚本,

  • 确保使用bash来执行脚本而不是sh. (2认同)

kar*_*res 5

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

rvm 1.9.3 exec camper_van
Run Code Online (Sandbox Code Playgroud)

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

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