【问题标题】:Switching rubies in shell script在 shell 脚本中切换红宝石
【发布时间】:2012-11-13 13:16:10
【问题描述】:

执行 bash shell 脚本时,我使用的是 ruby​​ 1.9.3。然后,在脚本中,我想切换到 JRub(我使用的是 rvm)。我尝试通过在脚本中执行 rvm use jruby 来切换到 JRuby,但这不起作用,它说:

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

当我在命令提示符下执行type rvm | head -n1 时,我得到:rvm is a function。所以我不确定这个问题。我想这可能是因为我使用 sudo (sudo rvm install jruby) 安装了 JRuby。所以我再次使用 sudo 运行了 shell 脚本。我再次收到错误消息。

如何使用 rvm 从 bash shell 脚本中切换 rubies?

谢谢

【问题讨论】:

    标签: shell rvm jruby


    【解决方案1】:

    我最终在之前的行中添加了这个:

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

    正如这个帖子中所解释的(抱歉 - 虽然我之前知道这个帖子,但我并没有完全掌握它):

    RVM doesn't switch Rubies

    【讨论】:

    • 我也是。即使我的.bash_profile 中有那一行,我仍然需要在运行rvm use ... 之前在shell 脚本中添加那一行
    【解决方案2】:

    /complete/path/to/rvm 你的 shell 似乎定义了一个 'rvm' 内置命令。

    【讨论】:

    • 感谢 hd1 - 获取 rvm 路径的最快方法是什么? .rvm 文件夹在我的 ~/ (home) - 我应该只使用 ~/.rvm/bin/rvm 使用 jruby 吗?
    • .rvm 文件夹在我的 ~/ (home) 中 - 在脚本中,我 cd'd 到 rvm 二进制文件夹,然后使用 ./rvm 使用 jruby。它不起作用,给出了同样的错误。
    • 尝试 rvm install jruby 然后 rvm 使用 jruby?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多