17

How to install Ruby 2.2.3 via apt on Ubuntu Wily? I tried sudo apt-get install ruby2.2-dev and sudo apt-get install ruby2.2 (What's the difference, btw) and both commands seem to have installed quite a bunch. However, there's no ruby executable afterwards.

5
  • do you absolutely install want to install ruby 2.2.3 via apt ? The *-dev package contains headers and files that * may need to function correctly. check the official ruby-lang.org it contains the information you need to install ruby 2.2.3 correctly
    – enzo
    Oct 28, 2015 at 16:46
  • please refer if it is useful [gorails.com/setup/ubuntu/15.10]
    – Ravan
    Oct 28, 2015 at 17:04
  • 1
    @maetsoh Why would I install every single package with apt, except ruby? I like package managers. Oct 29, 2015 at 6:48
  • Is Ruby part of the "alternatives" mechanism on Ubuntu? If not, it might be worthwhile using something like rbenv to manage Ruby installs. Especially if you need to use different versions of Ruby at the same time. Soft-linking can get a little tiresome when doing Rails development, etc.
    – user459652
    Oct 29, 2015 at 14:33
  • I use rbenv locally for switching versions, so it's worth the hassle.But on production I only need 1 ruby version, and then I prefer the standard package manager. I'll read up on the "alternatives" mechanism. (manpages.ubuntu.com/manpages/vivid/en/man8/…) Oct 29, 2015 at 16:34

2 Answers 2

17

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/.

1
  • same on debian jessie :/
    – holms
    Oct 5, 2016 at 18:00
8

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/

1
  • update-alternatives: error: alternative gem can't be slave of ruby: it is a master alternative May 30, 2016 at 9:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .