views:

314

answers:

2

The Ruby on Rails website recommends installing Ruby from source under Linux. I encountered a number of C library problems building ruby from source on a clean install of Unbuntu 9.

All the instructions I found on the net about installing ruby on ubuntu have involved using the prepackaged (.deb-based) ruby. Clearly this isn't what the rails people recommend.

When I did a clean source build of ruby I found Rubygems failed to install because the zlib extension didn't work.

Two problems occur:

1) The zlib extension isn't built.

Solution:

i) ensure zlib is uncommented in the Setup file within the extn directory of the ruby source, and

ii) ensure these zlib ubuntu packages are installed:

aptitude install zlib1g
aptitude install zlib1g-dbg
aptitude install zlib1g-dev
aptitude install zlibc

2) After fixing Problem 1 above (and doing a clean rebuild of ruby), zlib still doesn't work because the extension fails to load.

You can see that the module fails to load by running this and getting the output "false":

puts require 'zlib'

I observed this happens to any number of other C extensions in the extn directory, so it appears to be a more general problem with these extensions than just something zlib-specific.

To summarise:

  • My build of ruby finds the ruby-specific C zlib extension but it fails to load the zlib module.
  • This behaviour appears to happen to other extensions in /extn.

Is there a way I can find out why a module fails to load? some kind of trace/verbose mode?

+1  A: 

Did you install libzlib-ruby? Here's my typical Ubuntu initialization before installing Rubygems:

$ apt-get update
$ apt-get dist-upgrade
$ apt-get install build-essential -y
$ apt-get install rsync -y
$ apt-get install ruby ri rdoc irb ri1.8 ruby1.8-dev libzlib-ruby zlib1g libopenssl-ruby -y
Ryan McGeary
+1  A: 

I don't see what your problem is. You say that require 'zlib' returns false. But that means that it did work! If there were an error, you would get a LoadError exception.

Jörg W Mittag