How to set default to ruby 2.1.2?
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?
/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
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.