I have ruby 1.9.3 and 2.1.2. When I open the terminal by default it uses ruby 1.9.3 but I want to use ruby 2.1.2.

How can I set ruby 2.1.2 to be default?

4 Answers 4


/usr/bin/ruby is usually a link to /etc/alternatives/ruby, which in turn links to the executable of the default ruby version (e. g. /usr/bin/ruby1.9). You can change the configured default version with:

sudo update-alternatives --config ruby

If the desired version did not set up itself as alternative for ruby (e. g. if it isn't set up by the package manager), you can do it yourself with

sudo update-alternatives --install /usr/bin/ruby ruby /path/to/ruby2.1 <PRIORITY>

where <PRIORITY> is a positive integer. Then you can perform the first step.

For details see the manual of update-alternatives(8).


You should install RVM to manage your Ruby versions. To install RVM do

sudo apt-get install zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2 libxml2-dev libxslt-dev gawk libgdbm-dev libncurses5-dev automake libtool bison libffi-dev nodejs
\curl -sSL https://get.rvm.io | bash -s stable

If that breaks for some reason then follow the instructions here: https://stackoverflow.com/a/9056395/2376036

Then to make the default 2.1.2 do

rvm --default use 2.1.2
  • Hi, Thank you so much for your kind help, Yes, I followed your instructions but in the terminal while installing rvm it says "broken rvm package please check stackoverflow.com/a/9056395/497756" so I followed the path and get it to success, Thank you for your help
    – Rasool
    Oct 3, 2014 at 19:32
  • Glad I could help, please mark my answer as accepted so that people in the future can know what worked for you. I will add the extra context from your comment in my answer.
    – Termhn
    Oct 3, 2014 at 19:52

On Ubuntu 14.04 you can install ruby2.0 package. Currently the package offers version 2.0.0p384 (eventually the package might offer Ruby 2.1 or newer). This is the simples way how to install ruby binaries:

sudo apt install ruby2.0

Then you'll have binaries ruby2.0 and gem2.0. For replacing default ruby 1.9 by 2.0 you can do following (NOTE: you might break applications that strictly requires Ruby <= 1.9).

sudo update-alternatives --set /usr/bin/ruby ruby /usr/bin/ruby2.0 10
sudo update-alternatives --set /usr/bin/gem gem /usr/bin/gem2.0 10

Other possibilities are using some ruby version manager like rbenv or RVM. The first one is more complicated to setup, but less hacky than RVM. Both allow install almost any version of Ruby you would like to use.

  • 1
    Are you sure --install switch is correct. stackoverflow.com/a/1892889/525174 answer helped me, but only difference is uses --set switch. Aug 15, 2016 at 12:42
  • @Tombart there's an error in your code.
    – horaceT
    Sep 19, 2018 at 18:25
  • @horaceT Could you be more specific? Are you sure you're using the same Ubuntu version?
    – Tombart
    Sep 20, 2018 at 7:38
  • @Tombart I copied and pasted your first line. Here is the error : update-alternatives: error: alternative name (/usr/bin/ruby) must not contain '/' and spaces I have ubuntu 14.04
    – horaceT
    Sep 20, 2018 at 17:48

If you’re using Ubuntu 14.04 (Trusty) or newer then you can add this PPA:

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

Then you can install whichever package you want, for example

sudo apt-get install ruby2.2

To be able to build native extensions you'll need to dev package too

sudo apt-get install ruby2.2-dev

To easily switch between installed Ruby versions, install ruby switch:

sudo apt-get install ruby-switch

Commands of utiliy

ruby -v
ruby-switch --list


sudo ruby-switch --set ruby2.1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.