Soroush Rabiei
Soroush Rabiei

Reputation: 10878

How to change ruby version

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

Upvotes: 24

Views: 135206

Answers (5)

feigo808
feigo808

Reputation: 299

I tried all solutions listed above, but after I open a new terminal, the version always goes back to the old one. For me, the way I solved the problem is by running this rvm --default use **RUBY_VERSION_YOU_NEED**

Upvotes: 0

Srinivash
Srinivash

Reputation: 11

$/bin/bash --login`

Then add the Ruby version you have (for example 2.5, 2.7)

$rvm use 2.5

Upvotes: 1

dezman
dezman

Reputation: 19378

export PATH=$PATH:~yourusername/.rbenv/shims/ruby

This will set ruby in your shell to the current rbenv ruby.

You can put this line in your .bashrc or other init file.

Upvotes: 1

Felix
Felix

Reputation: 4716

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

Upvotes: 27

Gamaliel
Gamaliel

Reputation: 465

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/

Upvotes: 5

Related Questions