如何使用 RVM 设置默认的 Ruby 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7696633/
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 set default Ruby version with RVM?
提问by Michael Durrant
Ubuntu 11.
Ubuntu 11。
I do the following:
我执行以下操作:
$ rvm --default use 1.9.2and I get:
$ rvm --default use 1.9.2我得到:
Using /home/md/.rvm/gems/ruby-1.9.2-p180so that is good.
Using /home/md/.rvm/gems/ruby-1.9.2-p180所以这很好。
but when I now open a new terminal window I still get:
但是当我现在打开一个新的终端窗口时,我仍然得到:
$ ruby -v
$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
回答by ddd
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
如果将 RVM 源代码行放在 bashrc 中(以确保非交互式 shell 可以访问 RVM),则需要从 .bash_profile 中获取 .bashrc 并将以下内容作为 .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.
在您的 $HOME/.bashrc 中。这是确保交互式/登录和非交互式 shell 都能够正确查找和加载 RVM 的好方法。多用户安装通过 /etc/profile.d/rvm.sh 文件完成同样的事情。
After that, you should have no problems defining a default Ruby to use via
之后,您应该可以通过以下方式定义要使用的默认 Ruby 没有问题
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.
最好定义要使用的默认 gemset,以免污染您的“默认”或“全局” gemset。
If you are using non-interactive shells, be aware that they genereally operate in SH-compatibility mode which then requires you to set
如果您使用的是非交互式 shell,请注意它们通常在 SH 兼容模式下运行,这需要您设置
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.
在您的 $HOME/.profile 中,以便您加载 RVM,或者直接在您的脚本中进行设置。这样做的原因是当 bash 在 SH 模式下运行时,它不会直接加载 .bash_profile 或 .bashrc,因为 SH 不使用这些文件,而 bash 试图模仿 SH shell 的加载和执行过程。
回答by Michael Durrant
do an "rvm list" to see which Ruby versions you have installed.
执行“rvm 列表”以查看您安装了哪些 Ruby 版本。
then do this if you want to change the version only in one terminal session:
如果您只想在一个终端会话中更改版本,请执行以下操作:
rvm use 1.8.7
if you want to select the default version for this user account, do this:
如果要为此用户帐户选择默认版本,请执行以下操作:
rvm use --default 1.9.2
See:
看:
rvm use --help
See also this RailsCast:
另请参阅此 RailsCast:
http://railscasts.com/episodes/200-rails-3-beta-and-rvm
回答by user1322092
Late to party - anyway.
聚会迟到 - 无论如何。
You did correctly set the default ruby version: rvm --default use 1.9.2
您确实正确设置了默认的 ruby 版本: rvm --default use 1.9.2
However, you need to update your Gemfileto the target ruby, because RVM references that file to select the working ruby version when you open terminal , that's why it reverted to the previous ruby version.
但是,您需要将您Gemfile的 ruby更新为目标 ruby,因为当您打开终端时,RVM 会引用该文件来选择工作的 ruby 版本,这就是它恢复到以前的 ruby 版本的原因。
回答by Nimish
To Change the Default Version of ruby:
更改 ruby 的默认版本:
In Ubuntu
在Ubuntu 中
Go to default Terminal of Ubuntu and then follow the instructions:
转到 Ubuntu 的默认终端,然后按照说明进行操作:
1) Edit -> Profile Preferences
2) Select "Title and Command"
3) check "Run command as a login shell"
4) restart terminal
And after that run this command:
然后运行这个命令:
rvm --default use 2.2.4@gemset_name
rvm --default 使用 2.2.4@gemset_name

