简体   繁体   English

如何使用RVM设置默认的Ruby版本?

[英]How to set default Ruby version with RVM?

Ubuntu 11. Ubuntu 11。

I do the following: 我做以下事情:

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

Using /home/md/.rvm/gems/ruby-1.9.2-p180 so 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 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 如果您将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. 在$ 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. 这是确保交互式/登录和非交互式shell能够正确查找和加载RVM的好方法。 Multi-User installs accomplish the same thing via the /etc/profile.d/rvm.sh file. 多用户安装通过/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来使用,以免污染你的'默认'或'全局'gemsets。

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. 在$ HOME / .profile中,以便加载RVM,或直接在脚本中设置它。 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. 原因是当bash在SH模式下运行时,它不会直接加载.bash_profile或.bashrc,因为SH不使用这些文件,而bash正试图模仿SH shell的加载和执行过程。

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 http://railscasts.com/episodes/200-rails-3-beta-and-rvm

http://beginrescueend.com/ http://beginrescueend.com/

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 Gemfile to 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,因为RVM引用该文件以在打开终端时选择工作ruby版本,这就是它恢复到以前的ruby版本的原因。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM