55

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]

alex
  • 479,566
  • 201
  • 878
  • 984
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
  • 1
    What version of rvm? I'm on Ubuntu 10, but I'm skeptical that'd be able to make a difference. Anything in ~/.rvmrc? – Dave Newton Oct 08 '11 at 12:12
  • What happens if you run `rvm list default` in a new terminal window? – bricker Oct 08 '11 at 12:14
  • 1
    Try running `rvm --default 1.9.2` instead. That works for me. – Frost Oct 08 '11 at 15:21
  • Did you accidentally put the line to load rvm in your `bashrc` instead of your `bash_profile`? – jdeseno Oct 08 '11 at 15:55
  • jsdeseno yes I actually had it in both. I removed the .bashrc one but this did not help. I still have the path at the bottom, e.g. `PATH=/opt/homebrew/bin:/var/lib/gems/1.8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/durrantm/.rvm/bin:/home/durrantm/.rvm/bin:/home/durrantm/Downloads/android/android-sdk-linux_x86/tools:/Downloads/android/android-sdk-linux_x86/platform-tools` – Michael Durrant Oct 08 '11 at 22:10
  • bricker, rvm list default gives: `Default Ruby (for new shells) ruby-1.9.2-p180 [ i386 ] ` – Michael Durrant Oct 08 '11 at 22:11
  • both a new shell ruby -v gives 1.8.7 – Michael Durrant Oct 08 '11 at 22:11
  • martin, that is good but does not affect a new shell window's ruby -v – Michael Durrant Oct 08 '11 at 22:12
  • Dave - `durrantm@michael-laptop:~$ cat .rvmrc export rvm_path="/home/durrantm/.rvm" durrantm@michael-laptop:~$ cat .rvm cat: .rvm: Is a directory durrantm@michael-laptop:~$ ls .rvm archives config environments gems help LICENCE man README scripts tmp usr wrappers bin contrib examples gemsets lib log patches rubies src user VERSION durrantm@michael-laptop:~$` – Michael Durrant Oct 08 '11 at 22:14
  • Please note that the order is wrong in the command you typed! the "--default" option goes right after the "rvm use" , followed by the version number, e.g. "rvm use --default 1.9.2" –  Oct 10 '11 at 18:16

4 Answers4

61

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.

ddd
  • 1,925
  • 12
  • 19
37

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/

4

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.

user1322092
  • 4,020
  • 7
  • 35
  • 52
0

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

Nimish
  • 1,053
  • 13
  • 29