Compiling Ruby 1.9 with GCC 4.4

28 04 2009

Got the 1.9 pickaxe, so it’s definitely time to get Ruby 1.9 installed alongside 1.8. It turns out that if you try to build Ruby 1.9 with GCC 4.4 by means of the typical ./configure; make; sudo make install, you will hit a wall on the make step. I’m running into this while evaluating Fedora11 snap1, still in beta. The issue is that GCC 4.4 introduces a few changes that will impede ruby 1.9 from compiling without some minor adjustments.

These are the steps to get going:
1. Download, verify and unpack Ruby 1.9.
$ wget
$ md5sum ruby-1.9.1-p0.tar.gz
50e4f381ce68c6de72bace6d75f0135b ruby-1.9.1-p0.tar.gz #verify that hash matches
$ tar xvf ruby-1.9.1-p0.tar.gz
$ cd ruby-1.9.1-p0

At this point, we have verified and extracted the ruby 1.9 source code. Go ahead and create your platform’s compile configuration. There are many flags you can pass. To see them all, type ./configure –help. I’ve chosen to keep the libraries in their default locations, and suffix the binaries with ’19’ (leaving your 1.8 ruby installation intact). Some folks prefer to install it on a completely different path to avoid this very issue, by using the –prefix-path flag instead. That’s up to you.
./configure --program-suffix=19 --disable-pthread
At this point, you may be tempted to type “make”. If you do, you’ll get the following error:

cont.c:90:6: error: #elif with no expression
cont.c:270:6: error: #elif with no expression
cont.c:317:6: error: #elif with no expression
make: *** [cont.o] Error 1

The resolution is to edit the cont.c file to go on. Open it up, and change the lines 90, 270 and 317 from #elif to #else.

Now, carry on as usual:
$ make
$ make test #make sure everything's sane
$ sudo make install #or su -, or whatever it is you kids use to gain admin privileges these days

You’re done. irb will open up the console on ruby 1.8, and irb19 will open it in ruby 1.9. Similarly, point your scripts to the ruby19 binary instead of ruby.

You can now try out some of the new ruby 1.9 features in irb19:
irb(main):001:0> [1,2].inject(:+) #new injections
=> 3
irb(main):002:0> {a: 'a_val', b: 'b_val'} #new hash synthax
=> {:a=>"a_val", :b=>"b_val"}
irb(main):003:0> p = -> a,b,c {a+b+c} #lambda shorthand
=> #
=> true
irb(main):005:0> beta_string = 'ß' #utf-8 strings
=> "ß"
irb(main):006:0> π = 3.14 # and variables
=> 3.14
irb(main):007:0> π * 5
=> 15.7

Now, let’s see what the fuzz is all about. I tried running the the full ruby benchmark suite, but I got a nasty kernel panic:Apr 27 23:03:45 hgnux kernel: Critical temperature reached (95 C), shutting down.Guess I need a laptop that sucks less to run it. This isn’t over though: I’ll stick my laptop in the freezer if I have to, just to run the full benchmark suite.

Instead, let’s run and benchmark the most inefficient piece of crap on both versions of ruby. Recursion will do the trick. Let’s calculate factorials and fibonaccis left and right. Save this script somewhere:

require 'benchmark'
include Benchmark
def fact(n)
  n == 1 ? 1 : n*fact(n-1)

def fib(n)
  if n == 0 || n == 1
    fib(n-1) + fib(n-2)

puts "Ruby #{RUBY_VERSION} patch #{RUBY_PATCHLEVEL}"

bm do |r| do 
    (1..35).each do |n|

Now, invoke it with both your ruby and your ruby19 binaries:

Ruby 1.8 vs. Ruby 1.9 running recursion.rb

Ruby 1.8 vs. Ruby 1.9 running recursion.rb

$ ruby recursion.rb 
Ruby 1.8.6 patch 287
      user     system      total        real
155.320000  45.950000 201.270000 (229.181959)

$ ruby19 recursion.rb 
Ruby 1.9.1 patch 0
      user     system      total        real
 16.030000   0.100000  16.130000 ( 16.852891)

Sweet! I’ve also included the results of vmstat + vmplot of these runs. Most impressive is the minimized number of system interrupts on the ruby 1.9 version.

Ruby downloads:
GCC 4.4 porting notes:
Extended vmplot:
Ruby benchmark suite:


Installing FANN and ruby-fann on Fedora Core 9

1 08 2008

Content moved to

Stop spam on sendmail

16 09 2006

Content moved to

Setting up httpd as a proxy for Tomcat

5 09 2006

Content moved to

Run commands on boot for Fedora Core.

21 08 2006

Content moved to

Installing vanilla Tomcat on Fedora Core.

21 08 2006

Content moved to