Install ruby 2.2.3 via apt

Ok, this worked for me on vivid at least:

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

On wily, I get an error because the URL http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu/dists/wily/main/binary-amd64/ is missing, there's only http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu/dists/devel/main/binary-amd64/.


apt-get install ruby2.2 does give you a ruby executable - it's just called ruby2.2. Gem and irb are the same (i.e. gem2.2 install bundler will work, irb2.2 will give you an irb prompt.)

This is normal in Ubuntu and the alternatives system generally means you don't have to care about it, but for whatever reason ruby isn't managed by alternatives in Ubuntu. But we can make it:

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

Running this will register ruby with the alternatives system and, as there's only one choice, set ruby 2.2 as default. This will create symlinks and let you use ruby/gem/ etc. without adding 2.2 on the end.

This is a slightly updated version of instructions found at https://leonard.io/blog/2012/05/installing-ruby-1-9-3-on-ubuntu-12-04-precise-pengolin/

Tags:

Ruby

Apt

15.10