How to set default Ruby version with RVM?

寵の児 提交于 2019-11-26 19:23:32

问题


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]


回答1:


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.




回答2:


do an "rvm list" to see which Ruby versions you have installed.

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:

http://railscasts.com/episodes/200-rails-3-beta-and-rvm

http://beginrescueend.com/




回答3:


Late to party - anyway.

You did correctly set the default ruby version: 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.




回答4:


To Change the Default Version of ruby:

In Ubuntu

Go to default Terminal of Ubuntu and then follow the instructions:

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



来源:https://stackoverflow.com/questions/7696633/how-to-set-default-ruby-version-with-rvm

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