如何使用RVM设置默认的Ruby版本? [英] How to set default Ruby version with RVM?

查看:420
本文介绍了如何使用RVM设置默认的Ruby版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ubuntu 11.

我执行以下操作:

$ rvm --default use 1.9.2 然后我得到:

Using /home/md/.rvm/gems/ruby-1.9.2-p180 这样很好.

但是当我现在打开一个新的终端窗口时,我仍然得到:

$ ruby -v

ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]

解决方案

如果将RVM源代码行放入bashrc中(以确保非交互式shell可以访问RVM),则需要提供.bashrc源代码从您的.bash_profile中获取,其中以下内容是您的.bash_profile中的最后一行

if [ -f "$HOME/.bashrc" ]; then
  source $HOME/.bashrc
fi

这个前提是你有

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

在$ HOME/.bashrc中.这是确保交互式/登录和非交互式外壳程序都能正确找到并加载RVM的好方法.多用户安装通过/etc/profile.d/rvm.sh文件完成相同的操作.

在那之后,定义默认的Ruby来使用应该没有问题

rvm 1.9.2 --default

rvm use 1.9.2@mygemset --default

最好定义要使用的默认gemset,以免污染您的"default"或"global" gemset.

如果您使用的是非交互式外壳,请注意它们通常在SH兼容模式下运行,然后需要您进行设置

BASH_ENV="$HOME/.bashrc"

在$ HOME/.profile中

以便加载RVM,或直接在脚本中进行设置.原因是当bash在SH模式下运行时,它不会直接加载.bash_profile或.bashrc,因为SH不使用这些文件,并且bash试图模仿SH shell的加载和执行过程. >

Ubuntu 11.

I do the following:

$ rvm --default use 1.9.2 and I get:

Using /home/md/.rvm/gems/ruby-1.9.2-p180 so that is good.

but when I now open a new terminal window I still get:

$ ruby -v

ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]

解决方案

If you put the RVM source line in your bashrc (in order to ensure that non-interactive shells have access to RVM), you will need to source .bashrc from your .bash_profile with the following as the last lines in your .bash_profile

if [ -f "$HOME/.bashrc" ]; then
  source $HOME/.bashrc
fi

This pre-supposes that you have

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

in your $HOME/.bashrc. This is a good way to ensure that both interactive/login and non-interactive shells are able to find and load RVM correctly. Multi-User installs accomplish the same thing via the /etc/profile.d/rvm.sh file.

After that, you should have no problems defining a default Ruby to use via

rvm 1.9.2 --default

or

rvm use 1.9.2@mygemset --default

Its better to define a default gemset to use so as not to pollute your 'default' or 'global' gemsets.

If you are using non-interactive shells, be aware that they genereally operate in SH-compatibility mode which then requires you to set

BASH_ENV="$HOME/.bashrc"

in your $HOME/.profile in order you load RVM, or to set that within your script directly. The reason for this is that when bash is operating in SH mode it does not directly load .bash_profile or .bashrc as SH doesn't use those files, and bash is attempting to mimic the loading and execution process of the SH shell.

这篇关于如何使用RVM设置默认的Ruby版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆