Saturday, January 27, 2007

How to install Ruby 1.8.5 from source on Ubuntu

Well, it ends up that installing Ruby 1.8.5 and the associated Gems is a pain on Ubuntu. I'm here to take away that pain, yo.

Installing Ruby 1.8.5 from source

First, get the source tarball of 1.8.5 from the ruby lang web page, and put it in /usr/local/src
sudo tar -xvzf ruby-1.8.5-p12
cd ruby-1.8.5-p12
sudo ./configure
sudo make
sudo make install
If all goes well, you're in business. But if it complains about "cannot open crt1.o"
(which is likely on Ubuntu), you'll divine on google that it needs a "glibc-devel-2.3.3-74.i386" package. But I've done the legwork already, and under ubuntu, it's actually called "libc6-dev"
sudo apt-get install libc6-dev
So try making Ruby again. It should be ok. If not, well, it's not documented here, since I didn't run into that problem.

What I did run into was more pain installing Gems.

Installing Ruby Gems from source

Again, go get the source tarball of ruby gems, and put it into /usr/local/src
sudo tar -xvzf rubygems-0.9.1
cd rubygems-0.9.1
sudo ruby setup.rb

Now, if all is well, you're golden. But since this is Ubuntu, it's likely that you're missing zlib. So, some people seemed to have been able to get it to work from using the "zlib-ruby" package. What I had to do was install zlib from source.

Installing Ruby Zlib from source

Get the Ruby Zlib source and again put it into /usr/local/src/
sudo tar -xvzf ruby-zlib-0.6.0
cd ruby-zlib-0.6.0
sudo ruby extconf.rb

If that didn't work, most likely, you got a bunch of stuff that said:
checking for deflateReset() in -lz... no
checking for deflateReset() in -llibz... no
checking for deflateReset() in -lzlib... no

That means that you need the headers for zlib. So install the package "zlib1g-dev"
sudo apt-get install zlib1g-dev

Then try it again. That should work, and once you get zlib installed, you can get gems up and running.


  1. I come across strange rails error when I try to access controller with session (usng db session)

    NameError in StoreController#index

    uninitialized constant StoreController::Cart

    /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:477:in `const_missing'
    app/controllers/store_controller.rb:9:in `find_cart'
    app/controllers/store_controller.rb:6:in `index'

    If I do make test-all one of the test fails (something calles test-sdbm)

    Any good idea?

  2. I'd recommend going with Ruby 1.8.4 that's in the Ubuntu list, since it seems like you've had trouble with installing 1.8.5 from source also. Even though I got it to work, I've went back to 1.8.4, due to whatever reason I can't remember now, and it's been fine...the problem wasn't the ruby version.

    But in any case, for your problem, I've only seen that if the gems were including files incorrectly, I typed the class name wrong, or I was using it in the wrong scope. I assume Cart is a model object, and rails somehow doesn't know to look outside of the StoreController for the Cart.

    I'd try using Ubuntu's standard installs for ruby and rails to see if you get the same error, and then vary one or the other to see which part is giving you the error, then change that part to a version where it does work.