37

I'm running Ubuntu 12.04 LTS, and installed Ruby via RVM.

The problem is, when I type ruby -v into the terminal, it says that my Ruby version is 1.8.7, and using the shotgun gem for Sinatra also says that I'm running Ruby 1.8.7.

But when I type rvm list it shows that the only version of Ruby that I have installed is 2.0.0 and it is my current and default version.

I installed Ruby 2.0.0 via RVM and it is the only version I had installed on my machine.

Now when I tried to install Rails 4 but got an error saying that I need Ruby 1.9 or higher.

How do I know what version am I really on, and how do I set 2.0.0 as my only version?

Community
  • 1
  • 1
Ordep81
  • 967
  • 4
  • 13
  • 18
  • I suspect that you haven't tried reading through [the installation directions for RVM](http://rvm.io/rvm/install), which would have had you use `rvm --default use 2.0.0` to set your default Ruby, which will be used automatically when you open a shell. This is the most important part of what @ansh0l recommended. – the Tin Man Sep 01 '13 at 20:28

4 Answers4

24

On your terminal, try running:

which -a ruby

This will output all the installed Ruby versions (via RVM, or otherwise) on your system in your PATH. If 1.8.7 is your system Ruby version, you can uninstall the system Ruby using:

sudo apt-get purge ruby

Once you have made sure you have Ruby installed via RVM alone, in your login shell you can type:

rvm --default use 2.0.0

You don't need to do this if you have only one Ruby version installed.

If you still face issues with any system Ruby files, try running:

dpkg-query -l '*ruby*'

This will output a bunch of Ruby-related files and packages which are, or were, installed on your system at the system level. Check the status of each to find if any of them is native and is causing issues.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
12

Run this command:

rvm get stable --auto-dotfiles

and make sure to read all the output. RVM will tell you if something is wrong, which in your case might be because GEM_HOME is set to something different then PATH.

Community
  • 1
  • 1
mpapis
  • 52,729
  • 14
  • 121
  • 158
  • I needed to type in /bin/bash --login. Problem now is that I have to do this everytime I open or restart terminal. Is there anyway around this? – Ordep81 Sep 02 '13 at 22:11
  • 1
    if you run `rvm use` without sourcing rvm it will show you this link https://rvm.io/integration/gnome-terminal - maybe it is not your terminal - but in every terminal there should be option for this, just check preferences – mpapis Sep 02 '13 at 23:49
7

The ruby version 1.8.7 seems to be your system ruby.

Normally you can choose the ruby version you'd like, if you are using rvm with following. Simple change into your directory in a new terminal and type in:

rvm use 2.0.0

You can find more details about rvm here: http://rvm.io Open the website and scroll down, you will see a few helpful links. "Setting up default rubies" for example could help you.

Update: To set the ruby as default:

rvm use 2.0.0 --default
Matthias
  • 4,355
  • 2
  • 25
  • 34
  • 1
    "rvm use 2.0.0" is not the full command needed to have RVM automatically use 2.0 each time a shell is opened. The `--default` flag is required to set the default. – the Tin Man Sep 01 '13 at 20:29
1

If you have access to a console in the context you are investigating, you can determine which version you are running by printing the value of the global constant RUBY_VERSION.

Ivar
  • 5,102
  • 2
  • 31
  • 43