Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change ruby version

Tags:

ruby

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
like image 639
sorush-r Avatar asked Feb 26 '14 07:02

sorush-r


2 Answers

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).

like image 146
Felix Avatar answered Oct 23 '22 14:10

Felix


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/

like image 38
Gamaliel Avatar answered Oct 23 '22 14:10

Gamaliel