Switching rubies in shell script

痴心易碎 提交于 2019-12-24 05:54:09

问题


When executing a bash shell script I am using ruby 1.9.3. Then, within the script, I want to switch to JRub (I'm using rvm). I tried switching to JRuby by doing rvm use jruby within the script, but this didn't work, it said:

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.sh: line 10: jruby: command not found

When I do type rvm | head -n1 at the command prompt, I get: rvm is a function. So I'm not sure of the problem. I thought it might be because I installed JRuby using sudo (sudo rvm install jruby). So I ran the shell script again using sudo. Again I received the error.

How can I switch rubies from within a bash shell script with rvm?

Thanks


回答1:


I ended up adding this to the line before:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

as explained in this thread (sorry - though I was aware of this thread before, I didn't quite grasp it):

RVM doesn't switch Rubies




回答2:


/complete/path/to/rvm your shell seems to have an 'rvm' builtin command defined.



来源:https://stackoverflow.com/questions/13361382/switching-rubies-in-shell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!