20

Ruby 1.8 and 1.9 are installed in my Ubuntu machine. I've just installed Ruby 2.0.0 from ppa:brightbox/ruby-ng-experimental to install a bundle which requires 2.0.0. Now all 1.8, 1.9 and 2.0 are installed though I can't tell bundle to use 2.0:

$ bundle install
$ Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0

RVM fails to change version:

$ rvm 2.0
$ ruby-2.0.0-p451 is not installed.
$ To install do: 'rvm install ruby-2.0.0-p451'

RBENV also does not recognize 2.0:

$ rbenv global 2.0.0-p451
$ rbenv: version `2.0.0-p451' not installed
sorush-r
  • 10,036
  • 16
  • 85
  • 168

2 Answers2

22

There is lots of advise in the comments to your question, some of it is advanced-ish rbenv or rvm usage.

My advice: Decide on how to manage multiple rubies - either use your OS package manager (in your case the apt-get/PPA stuff) OR rvm OR rbenv.

For the OS package manager, there should be a way to call ruby with version explicitely (e.g. /usr/bin/ruby1.9.3), or research on and call update-alternative. As bundler comes with a gem, you might get the interpreters confused here.

For rvm, change ruby version with rvm use 2.5.1 (once it is installed).

For rbenv I actually do not know but it should be trivial, too (and people are happy with it; it just happens that I tried rvm first and it worked like a charm, never evaluated rbenv).

I usually install one "system" ruby (apt-get install ruby1.9.3) and use rvm afterwards. You can still switch to the packaged "production" ruby with rvm use system.

Update 2017: Most distros ship with a ruby version installed already, so you probably don't have to install it manually. Run ruby -v or which ruby to see if a ruby interpreter is already installed.

In your case I would probably deinstall all system rubys (apt-get purge ...), remove the PPAs, remove your ~/.rvm and rbenv and start from scratch (install packaged stable ruby, then rvm and use rvm (r.g. rvm install 2.3.1) from there on).

Felix
  • 4,093
  • 2
  • 27
  • 42
4

Adding the repository If you’re using Ubuntu 14.04 (Trusty) or newer then you can add the package repository like this:

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:brightbox/ruby-ng
$ sudo apt-get update

Install ruby switch

$ sudo apt-get install ruby-switch

Commands of utiliy

ruby -v
ruby-switch --list

Example

$ sudo ruby-switch --set ruby2.1

Hope this help you.

From: https://www.brightbox.com/docs/ruby/ubuntu/

Gamaliel
  • 345
  • 3
  • 5
  • Trying to install ruby-switch gave me this: Package ruby-switch is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'ruby-switch' has no installation candidate – Luciano Brum Jan 03 '21 at 19:52
  • 1
    Maybe is outdated, I mean, check if the repository is available in your Ubuntu version. As I know at this date Brightbox doesn't have Ruby release to Ubuntu 20. That's my last try and need to install it another way. – Gamaliel Jan 05 '21 at 02:12