Debian: Install newer version of Ruby

Warning: This page is a part of an archive now and will be removed in the future.

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][/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:

Source Code

  1. /root/ruby-2.2.2/lib/fileutils.rb:864:in `utime': No such file or directory @ utime_internal - /usr/local/bin/ruby (Errno::ENOENT)
  2. from /root/ruby-2.2.2/lib/fileutils.rb:864:in `block in install'
  3. from /root/ruby-2.2.2/lib/fileutils.rb:1570:in `block in fu_each_src_dest'
  4. from /root/ruby-2.2.2/lib/fileutils.rb:1584:in `fu_each_src_dest0'
  5. from /root/ruby-2.2.2/lib/fileutils.rb:1568:in `fu_each_src_dest'
  6. from /root/ruby-2.2.2/lib/fileutils.rb:859:in `install'
  7. from ./tool/rbinstall.rb:158:in `install'
  8. from ./tool/rbinstall.rb:334:in `block in <main>'
  9. from ./tool/rbinstall.rb:757:in `call'
  10. from ./tool/rbinstall.rb:757:in `block in <main>'
  11. from ./tool/rbinstall.rb:754:in `each'
  12. from ./tool/rbinstall.rb:754:in `<main>'
  13. make: *** [do-install-all] Fehler 1
  14. **** Installation fehlgeschlagen. Breche Paket-Erzeugung ab.
  15. Räume auf...OK
  16. Auf Wiedersehen!
Display All

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):

Source Code

  1. *****************************************
  2. **** Debian package creation selected ***
  3. *****************************************
  4. Das Paket wird entsprechend dieser Vorgaben erstellt:
  5. 0 - Maintainer: [ root@KittMedia ]
  6. 1 - Summary: [ Package created with checkinstall 1.6.2 ]
  7. 2 - Name: [ ruby ]
  8. 3 - Version: [ 2.2.2 ]
  9. 4 - Release: [ 1 ]
  10. 5 - License: [ GPL ]
  11. 6 - Group: [ checkinstall ]
  12. 7 - Architecture: [ amd64 ]
  13. 8 - Source location: [ ruby-2.2.2 ]
  14. 9 - Alternate source location: [ ]
  15. 10 - Requires: [ ]
  16. 11 - Provides: [ ruby ]
  17. 12 - Conflicts: [ ]
  18. 13 - Replaces: [ ]
  19. Geben Sie die betreffende Nummer ein, um die Vorgaben zu ändern:
Display All

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.
About the Author
Ich bin Webentwickler in Stuttgart und administriere Server seit vielen Jahren. In diesem Blog erstelle ich hauptsächlich Tutorials für andere Webentwickler, Webdesigner und Serveradministratoren.
I’m a web developer in Stuttgart, Germany, and server administrator since many years. This blog mainly contains a tutorial set for other web developer, web designer and server administrators.

2,212 times read

Comments 1

  • A. Donoso -

    Geat work ! thanks. It works for ruby2.2.4 too.

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.