bash 如何在 shell 脚本中使用 rvm
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19954043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to use rvm in shell scripting
提问by user1328342
is it possible to load rvm in shell script . can any one give an example of it. when i try a shell script . i am using ubuntu system
是否可以在 shell 脚本中加载 rvm。谁能举个例子。当我尝试使用 shell 脚本时。我正在使用 ubuntu 系统
#!/bin/bash
rvm use 1.9.3
it gives me error
它给了我错误
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.
回答by jbr
You can just include rvm in your script by doing:
您可以通过执行以下操作在脚本中包含 rvm:
source ~/.rvm/scripts/rvm
then rvm should be available to your script,
那么 rvm 应该可用于您的脚本,
回答by kares
for simply executing a command against a RVM managed Ruby (or system Ruby) do :
为了简单地针对 RVM 管理的 Ruby(或系统 Ruby)执行命令,请执行以下操作:
rvm 1.9.3 exec camper_van
this assumes rvm use 1.9.3
and gem install camper_van
happened previously which provides the camper_van
executable
这假设rvm use 1.9.3
并且gem install camper_van
之前发生过,它提供了camper_van
可执行文件
NOTE: RVM is expected to be loaded already - which it usually is for scripts started under your user (the RVM is not a function, selecting rubies with 'rvm use ...'
confirms it's there already).
注意:RVM 预计已经加载 - 通常用于在您的用户下启动的脚本(RVM is not a function, selecting rubies with 'rvm use ...'
确认它已经存在)。
回答by Amol Pujari
# 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