Compiling Ruby 1.9.2 on Debian Lenny

I’ve just recently been setting up my Debian Lenny web server to run Rails apps. So I thought I might document some of what I did for posterity and as a way to give back a little in return for all those blog posts and general instructional texts found on the Internet that have helped me over the years.

Ruby 1.9.0 is already available in the Debian Lenny repositories, so if you’re happy with this version you can of course just install the ruby1.9 package and be done with it. You could also check what backports are available and stuff. But I can’t leave well enough alone though so if you’re like me, read on.

Ruby 1.9.2 has been officially released. Shiny.

Of particular note to me was this entry in the FAQ section:

The standard library is installed in /usr/local/lib/ruby/1.9.1

Seems a bit weird, but OK. Yay for backwards compatibility I guess?

Note about RubyGems

RubyGems comes with Ruby 1.9.x so you won’t need to install it separately. There is some debate about how RubyGems should work on Debian and the version of RubyGems that is available in the Debian repositories has been customised. I personally prefer just to have the standard RubyGems working in the standard way. So I’m fine with RubyGems coming along with Ruby 1.9.×.

You’ll need at least the libmysqlclient15-dev package before installing the mysql gem in order to use MySQL with your Rails apps, but as people don’t always use MySQL as their database engine and this post is just about compiling Ruby, I’m not going to get into that stuff here.

Forward, not backward, upward, not forward and always twirling, twirling, twirling towards freedom

I’m using aptitude for my package management and the root account, so there’ll be no ‘sudo’ command used herein. Adjust your commands accordingly if you don’t do things this way.

We will be installing Ruby into the /usr/local directory, change to the /usr/local/src directory:

1
# cd /usr/local/src

This is where we’re going to be doing our work.

Next, we need to ensure that we’ve got all the required build dependencies for compiling Ruby:

1
# aptitude install libc6-dev libssl-dev libreadline5-dev zlib1g-dev

The libc6-dev package should be already installed on Debian Lenny. But I thought I’d list it anyway.

Download the Ruby 1.9.2 source files:

1
# wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p0.tar.gz

Extract the files from the tar ball:

1
# tar xvzf ruby-1.9.2-p0.tar.gz

Change into the newly extracted directory:

1
# cd ruby-1.9.2-p0

Run autoconf:

1
# autoconf

Run the configure script with the desired options:

1
# ./configure --prefix=/usr/local --with-openssl-dir=/usr --with-readline-dir=/usr --with-zlib-dir=/usr

Lots of output should fly by as the configure script does its thing.

Now we make:

1
# make

Even more output should start flying by in your shell terminal.

Obsessive compulsive software compilation

Usually at this point the next step is to type the ‘make install’ command, but wait! I must digress for a moment.

The only thing I hate about compiling new software (other than when it doesn’t work) is that once I’ve installed the software into the sub-directories of /usr/local there’s often no easy way to uninstall all the files if and when the time comes to do so. Some source includes the ability to run ‘make uninstall’ from the original directory that you compiled the software in, but in my experience to date, most don’t. I could install everything into a single sub-directory (such as /usr/local/ruby) but this can cause issues later on when other software might be expecting compiled binaries and other files to be in certain locations when they’re not. There are mitigations for this issue, but I think I know of a better solution.

Debian package management is awesome. It allows you to easily add and remove packages at will with succinct commands, while dependencies are largely taken care of transparently. But what if like me, you’re a bit obsessive compulsive about keeping your file system neat and you’d like to have a similar capability even when compiling your own stuff from source? Debian to the rescue! If you don’t already have it, grab the checkinstall package:

1
# aptitude install checkinstall

The checkinstall package will allow you to install your newly compiled software as a package that can then be managed (and most importantly to me, removed) like any other Debian package.

Now we’re going to install Ruby using checkinstall:

1
# checkinstall -D make install

The ‘-D’ flag means that we’re going to build a Debian package. Now checkinstall will ask you if you want to create some documentation for your new Ruby package:

1
2
The package documentation directory ./doc-pak does not exist. 
Should I create a default set of package docs?  [y]:

You don’t have to do this, but it might be kind of fun. So let’s answer ‘y’.

Now you’ll get:

1
2
3
Please write a description for the package.
End your description with an empty line or EOF.
>>

So we can type in a description, maybe something like:

1
>> Ruby Programming Language (MRI 1.9.2)

Then hit Enter and then Enter again as the description ends when you enter an empty line.

Next up you should get something that looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
*****************************************
**** Debian package creation selected ***
*****************************************

This package will be built according to these values: 

0 -  Maintainer: [ root@server.domain.com ]
1 -  Summary: [ Ruby Programming Language (MRI 1.9.2) ]
2 -  Name:    [ ruby-1.9.2 ]
3 -  Version: [ p0 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ ruby-1.9.2-p0 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ ruby-1.9.2 ]

Enter a number to change any of them or press ENTER to continue:

If you’re happy with all that, then just hit Enter again. If you want to change anything, type the number of the line you want to change and hit Enter. Let’s change the email address of the maintainer, type ‘0’, then Enter. You should get:

1
2
# Enter the maintainer's name and e-mail address:
>>

Let’s just type in an email address and hit Enter:

1
2
# Enter the maintainer's name and e-mail address:
>> not@any.com

We should get back to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
This package will be built according to these values: 

0 -  Maintainer: [ not@any.com ]
1 -  Summary: [ Ruby Programming Language (MRI 1.9.2) ]
2 -  Name:    [ ruby-1.9.2 ]
3 -  Version: [ p0 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ ruby-1.9.2-p0 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ ruby-1.9.2 ]

Enter a number to change any of them or press ENTER to continue: 

Assuming we’re now happy, we can just hit Enter.

Another bunch of output should fly by in your terminal until it stops at:

1
2
3
4
5
6
Some of the files created by the installation are inside the build
directory: /usr/local/src/ruby-1.9.2-p0

You probably don't want them to be included in the package,
especially if they are inside your home directory.
Do you want me to list them?  [n]:

I’m not really interested in a list, so I type ‘n’ and checkinstall comes back with:

1
Should I exclude them from the package? (Saying yes is a good idea)  [y]:

I’ll take checkinstall’s word for it and type ‘y’. A bit more output is generated and then:

1
2
3
4
5
6
7
8
9
10
11
**********************************************************************

 Done. The new package has been installed and saved to

 /usr/local/src/ruby-1.9.2-p0/ruby-1.9.2_p0-1_amd64.deb

 You can remove it from your system anytime using: 

      dpkg -r ruby-1.9.2

**********************************************************************

So as you can see, a new .deb package has been created in the Ruby source directory that you can – in the future and should you wish – install in a similar way to any local .deb package. The only caveat is that I gather any dependencies of a package created in this way are not taken into account when it is installed.

But the important thing from my point of view is that Ruby 1.9.2 is now installed on my server and I can remove it quite easily by typing:

1
# dpkg -r ruby-1.9.2

Let’s just verify that Ruby is all happy and working:

1
# ruby -v

This should produce something similar to:

1
# ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]

OK, and typing:

1
ruby -ropenssl -rzlib -rreadline -e "puts 'Ruby appears to be working OK with openssl, zlib and readline support.'"

You should get the expected output of:

1
# Ruby appears to be working OK with openssl, zlib and readline support.

Lastly, let’s check out RubyGems:

1
# gem env

This should produce something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/1.9.1
     - /root/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

There you have it. Ruby 1.9.2 and RubyGems 1.3.7 installed on Debian Lenny, using checkinstall for easy removal.

  1. shinydragon says:

    http://www.qwantz.com/index.php?comic=1786

  2. Gaelian says:

    Who would have thought that dinosaurs are so wise.

  3. Guillaume says:

    Thank you for sharing this ! I ever wanted to find a way to manage properly my "built from source" piece of software !

  4. Gaelian says:

    No problem Guillaume, checkinstall is pretty awesome. Glad you found my post useful.

  5. wingfire says:

    Thanks alot for sharing this info!

  6. Daniel says:

    Thank you, that worked like a charm!

  7. jens says:

    thanks, great and very helpfull posting!!!! thanks!

  8. Chris says:

    Thank you so much! I've been pulling my head out trying to compile Ruby 1.9.2 properly on Debian and you helped out alot! Plus, I learned something new.

  9. Amy says:

    THANKS A LOT, SO USELESS

  10. Gaelian says:

    NO PROBLEM, AMY. MY GOAL IS TO PROVIDE NEGATIVE UTILITY.

  11. Amy says:

    WHY NEGATIVE UTILITY ?

  12. Gaelian says:

    @Amy: It was an ironic comment playing off your previous one.

    If you have an issue related to the topic of my post that you'd like some help with, shoot me an email and I'd be happy to try and help you out or at least point you in the right direction to get some help. But a strange comment posted in all-caps on a person's blog is not really the best netiquette.

  13. Andrew says:

    Thanks, excellent guide, worked perfect until the last step, gems seemed not working, but only problem was linux was searching for them at /usr/bin/gem i.e. not correct dir /usr/local/bin/gem... a symbolic link solved this, altough not sure if the most correct solution.

  14. Gaelian says:

    @Andrew: hmm, do you have /usr/local/bin set in your path? Dan Benjamin has a good write up: Using /usr/local that I found very helpful when starting out.

  15. Andrew says:

    Yes, my path var is i think debian standard PATH=/usr/local/bin:/usr/bin:/bin:/usr/games and later i similarly compiled sqlite3 with apropriate prefix and had the same problem. strange.

  16. Gaelian says:

    You're right about that being the default path for Debian. Just doing a little poking around and it looks like it's /etc/profile that sets "/usr/local/bin:/usr/bin:/bin:/usr/games" on Lenny as standard for a non-root user. And when you echo $PATH you're still seeing /usr/local/bin in the path before /usr/bin? Nothing else sneaking in there? If so, yes it's strange that your system isn't looking in /usr/local/bin first.

    If you haven't done so already, I might suggest that you head on over to the Debian User Forums and see if you can find anything there. If you work out what your problem is, I'd be interested to know the answer to the mystery. One really shouldn't have to be creating sym links in /usr/bin to stuff in /usr/local/bin under normal circumstances. It kind of goes some way to defeating the neat separation of concerns that you get by putting stuff in the /usr/local/ hierarchy.

  17. Nick says:

    Thanks a lot for your tutorial. It worked great for me. I run a server and I desperately needed an upgrade to ruby 1.9.2. I also learned about checkinstall. Great!

  18. Stonie says:

    Bloody brilliant post!! thanks ;) - works on wheezy and rails 1.9.3 with a minor tweak:

    1
    
    checkinstall --type=debian --install=yes --fstrans=no --pakdir='..'
    

  19. Stonie says:

    ps: please ignore the --- in my post, I had a crack at code formatting and lesstile seems to have not picked it up?

  20. Gaelian says:

    @Stonie: commenting, glad my post is still relevant.

    No worries about the formatting, I FTFY. :) With lesstile, I believe you need to put the beginning and ending '---' on its own line.

Post a comment


(lesstile enabled - surround code blocks with ---)