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?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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
/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>
<PRIORITY> is a positive integer. Then you can perform the first step.
For details see the manual of
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
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.
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