16

I’m using Ubuntu Linux. Below is the uname info

myuser@myinstance:~$ uname -a
Linux myinstance 3.18.0-52-generic #123-Ubuntu SMP Fri Feb 19 14:27:58 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

I’m trying to upgrade the version of Ruby on my machine, which is currently installed at

/usr/lib/ruby/1.9.1

I tried following the advice here — Install ruby 2.2.3 via apt, but unfortunately I get the error, “alternative path /usr/bin/ruby2.2 doesn't exist”. What is the right way to upgrade my system to use Ruby 2.2 or greater?

myuser@myinstance:~/racertracks$ sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby2.2 400 \
>  --slave /usr/bin/rake rake /usr/bin/rake2.2 \
>  --slave /usr/bin/ri ri /usr/bin/ri2.2 \
>  --slave /usr/bin/rdoc rdoc /usr/bin/rdoc2.2 \
>  --slave /usr/bin/gem gem /usr/bin/gem2.2 \
>  --slave /usr/bin/irb irb /usr/bin/irb2.2 \
>  --slave /usr/share/man/man1/ruby.1.gz ruby.1.gz /usr/share/man/man1/ruby2.2.1.gz \
>  --slave /usr/share/man/man1/rake.1.gz rake.1.gz /usr/share/man/man1/rake2.2.1.gz \
>  --slave /usr/share/man/man1/ri.1.gz ri.1.gz /usr/share/man/man1/ri2.2.1.gz \
>  --slave /usr/share/man/man1/rdoc.1.gz rdoc.1.gz /usr/share/man/man1/rdoc2.2.1.gz \
>  --slave /usr/share/man/man1/gem.1.gz gem.1.gz /usr/share/man/man1/gem2.2.1.gz \
>  --slave /usr/share/man/man1/irb.1.gz irb.1.gz /usr/share/man/man1/irb2.2.1.gz
update-alternatives: error: alternative path /usr/bin/ruby2.2 doesn't exist
Dave
  • 2,315

2 Answers2

19

Why not use ruby 2.3 which is available in the repositories for 16.04 and 17.10 with

sudo apt update

After the update is finished run:

sudo apt-get install ruby2.3 ruby2.3-dev

Or try ruby 2.4 or 2.5

You can get those via the brightbox PPA

  1. Add the repository and update

    sudo apt-add-repository ppa:brightbox/ruby-ng && sudo apt-get update
    
  2. install

    sudo apt-get install ruby2.4
    

    or for 18.04

    sudo apt-get install ruby2.5 ruby2.5-dev
    

Information on the status of packages in the aforementioned PPA can be found on the “Brightbox” team launchpad page.

Alternatively you could try reverse hacking the error alternative path /usr/bin/ruby2.2 doesn't exist by creating it with sudo mkdir /usr/bin/ruby2.2 and trying again.

Kulfy
  • 18,154
Elder Geek
  • 36,752
0

On Ubuntu 14.04 this worked for me to install ruby 2.4.1

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

Then install rbenv

    cd
    git clone git://github.com/sstephenson/rbenv.git .rbenv
    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
    echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

    git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
    echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
    source ~/.bash_profile

Now install ruby 2.4.1

rbenv install -v 2.2.3

To set 2.4.1 as a default use command rbenv global 2.4.1.

Temak
  • 141