问题 如何在shell脚本中使用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.

8709
2017-11-13 12:39


起源

可能重复 rvm安装无法正常工作:“RVM不是一个功能” - SirDarius


答案:


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

source ~/.rvm/scripts/rvm

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


13
2017-11-13 12:46



来源:未找到 - user1328342
确保使用bash来执行脚本而不是sh。 - jbr
如何使用bash。我创建了一个文件名qst.sh并在其中编写了代码。 - user1328342
而不是“sh qst.sh”使用“bash qst.sh” - Aparichith


对于简单地对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 ...' 确认它已经存在)。


2
2018-06-05 08:10





# 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

0
2017-11-13 12:47



我得到两个错误-fP:找不到和[[:找不到 - user1328342
什么是命令的输出 type -fP rvm。给定的代码段是shell脚本的一部分。 - Amol Pujari
Amol的代码需要bash,请确保您没有使用plain sh执行脚本。 - jbr
当我键入终端时,-fp类型的输出是/home/gaurav/.rvm/bin/rvm。实际上我是脚本的新手。当我写echo类型-fp rvm然后打印相同的命令 - user1328342
通过bash脚本添加这个,这个片段回声:“使用用户安装$ HOME / .rvm / scripts / rvm”。然后,当下一行尝试“rvm use ...”时,回到旧的“rvm不是函数”错误。如何在我们的Bash脚本中执行“使rvm成为函数”,以便我们可以实际使用它 - 比如设置ruby版本? - JosephK