in `require': no such file to load -- zlib (LoadError)

When trying to install rails on an Ubuntu 8.10, I got the following sort of error:


$ sudo gem install rails
... in `require': no such file to load -- zlib (LoadError)

The same error occurs when running:


$ sudo gem update

To fix this, ensure both the zlib runtime and development library are installed. On Ubuntu, the packages are zlib1g and zlib1g-dev.


$ sudo apt-get install zlib1g zlib1g-dev

Then recompile and install ruby (configure; make; make install). Now try gem update again. It should work.