Debian: Install newer version of Ruby

Debian Wheezy arrives with Ruby 1.9.3, which isn’t new enough for current software, for instance GitLab. At the moment in this case you need at least Ruby 2.1, which is not available as complete package by Debian itself. So you have to compile it for yourself and in this article I declare how it works.

At first you have to install all needed packages for the compilation process:
aptitude install checkinstall build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev

Then you have to download the current version from Ruby (or whichever you want/need) vid FTP. In my case it’s version 2.2.2:
wget [url]ftp://ftp.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz[/url]

Now the downloaded package will be unpacked and you go inside the directory of it:
tar xfz ruby-2.2.2.tar.gz && cd ruby-2.2.2

After that it will be configured:
./configure --prefix=/usr/local

You have to compile it now with make. The prefix -j declares the number of processor threads, which will be used for this process (standard: 1). I have a quad core processor with hyper threading, so I use -j 8;
make -j 8

The last step is to install the compiled source with checkinstall. Compared to make install it has the advantage the it uses the Debian package list so that you are able to remove it easily. Furthermore it generates a .deb package so that you can install it again without recompiling it.
If you use the command checkinstall without parameter you will receive the following error message:

/root/ruby-2.2.2/lib/fileutils.rb:864:in `utime': No such file or directory @ utime_internal - /usr/local/bin/ruby (Errno::ENOENT)
	from /root/ruby-2.2.2/lib/fileutils.rb:864:in `block in install'
	from /root/ruby-2.2.2/lib/fileutils.rb:1570:in `block in fu_each_src_dest'
	from /root/ruby-2.2.2/lib/fileutils.rb:1584:in `fu_each_src_dest0'
	from /root/ruby-2.2.2/lib/fileutils.rb:1568:in `fu_each_src_dest'
	from /root/ruby-2.2.2/lib/fileutils.rb:859:in `install'
	from ./tool/rbinstall.rb:158:in `install'
	from ./tool/rbinstall.rb:334:in `block in <main>'
	from ./tool/rbinstall.rb:757:in `call'
	from ./tool/rbinstall.rb:757:in `block in <main>'
	from ./tool/rbinstall.rb:754:in `each'
	from ./tool/rbinstall.rb:754:in `<main>'
make: *** [do-install-all] Fehler 1

**** Installation fehlgeschlagen. Breche Paket-Erzeugung ab.

Räume auf...OK

Auf Wiedersehen!Code language: PHP (php)

The problem is that checkinstall has a bug, which can be avoided by using the following command:
checkinstall --fstrans=no -D make install

Now you get the following selection list (I just have a German one but the English one should be similar in the main parts):

*****************************************
**** Debian package creation selected ***
*****************************************

Das Paket wird entsprechend dieser Vorgaben erstellt:

0 -  Maintainer: [ root@KittMedia ]
1 -  Summary: [ Package created with checkinstall 1.6.2 ]
2 -  Name:    [ ruby ]
3 -  Version: [ 2.2.2 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ ruby-2.2.2 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ ruby ]
12 - Conflicts: [  ]
13 - Replaces: [  ]

Geben Sie die betreffende Nummer ein, um die Vorgaben zu ändern:Code language: CSS (css)

The package name (2) is called ruby in this case. The problem is that the current official package is called ruby1.9.3 and thus is recognized as a newer package. This would be caused a installation error as long as you don’t edit the name. Just hit 2 and then hit enter to select the package name and rename it to (in my case) ruby2.2.2.

After that the installation should finish successfully. You can verify it with the command ruby -v, which should display something like this:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]

Additionally, as already said above, you can find the debian package in the current directory. In my case it is called ruby2.2.2_2.2.2-1_amd64.deb.

Leave a Reply

Your email address will not be published. Required fields are marked *