Monday, May 01, 2006

Ruby w/readline on Ubuntu

Getting Ruby running on Ubuntu 5.10 (Breezy) can be tricky. The issue is Breezy wants Ruby 1.8.3 from apt-get, and that has known problems with Rails 1.x. I usually recommend people install ruby 1.8.4 from source to work with Rails 1.1. But the base install of Ubuntu doesn't have many source build tools and libraries. This shows up in various places. For instance, running 'script/console' barfs complaining about missing the readline require. That is because irb wasn't built with it in the 1.8.4 build tree. Another issue you may have run into is support for rubygems is lacking due to a missing zlib development library. This may have messed up your install of Rails or various plugins.

Before we start read this guide: [1] Be sure to add the extra repositories, if you haven't yet.

Here are a bunch of commands that I executed to get Ruby built.


apt-get install build-essential
apt-get install bison byacc gperf
apt-get install zlib1g-dev
apt-get install libreadline5 libreadline5-dev
apt-get install libncurses5 libncurses5-dev temcap-compat
apt-get install libssl-dev


If you have previously tried to build it, then rm -rf ruby-1.8.4 and tar zxvf ruby-1.8.4.tar.gz; cd ruby-1.8.4; ./configure; make; sudo make install

Retest in your rails app: script/console. Everything should work.

The last install is for openssl development headers and libs. This is a Rake dependency in certain cases. (Not Rails specific.)

[1] http://ubuntuguide.org/

12 comments:

Craig Buchek said...

That should be 'zlib1g-dev', not 'zliblg-dev'. I.e. it's the numeral 1, not the letter L.

Ed Howland said...

Thanks for the correction.

Craig Buchek said...

I've documented on my Wiki how I installed Ruby 1.8.4 and Rails 1.1 on my Debian 3.1 system. It includes pretty much all the steps required, and lessons learned from Ed's blog and some other resources. Like Ed, I also ended up installing Ruby from source.

Anonymous said...

I spent TWO DAYS trying to get Ruby to compile properly in Ubuntu Edgy. I did not find reference to this problem on the Ubuntu site (even though some people have obviously known about it for two full releases), or just about anywhere else. I found a workaround for the zlib problem, but your instructions got it working. Thanks.

I just have to wonder why the installation of something that is supposed to work "out of the box", like Ruby in Ubuntu Dapper or Edgy, should have been so botched? And then the solution(s) so poorly documented?

Nathan said...

Dude, you are a lifesaver! I know this is old new for you guys, but I switched a Ubuntu a little while ago from Fedora and was completely happy until I had this openssl issue. It was totally hosing my Rails project work.

Anyway, following your instructions got all kinds of things working right again, like Capistrano! I appreciate the effort you took to make this info available!

William said...

I try to build it on edgy and got the following issue when doing make test-all:

1) Failure:
test_s_open_error(TestSDBM) [./sdbm/test_sdbm.rb:123]:
<Errno::EACCES> exception expected but none was thrown.

I hope you can help me out.

Ed Howland said...

Not sure which version of ruby you have tried. The best releases are 1.8.6 and 1.8.5-p2. I have tried the latter on both Dapper and Fiesty. I just ran 'make test-all' on 1.8.6 on fiesty and all tests pass. I guess I'd recommend upgrading to Fiesty if you haven't already and 1.8.6.

Sur Max said...

Hi Ed,
That worked out well, i was struggling to get the arrow keys work in my irb and with the help of this post by and compiling the ruby readline interface i got the irb and the console worked properly.

Thanks for the useful information.

Anonymous said...

Great post. This helped me quite alot. Below is my steps for a nice install on Dapper Drake.

1. "Uncomment out unviverse packages. etc/apt/sources.list"
2. "apt-get update"
3. "apt-get install build-essential"
4. "apt-get install build-essential
apt-get install bison byacc gperf
apt-get install zlib1g-dev
apt-get install libreadline5 libreadline5-dev
apt-get install libncurses5 libncurses5-dev
apt-get install libssl-dev"
5. "wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.gz"
"tar xzvf ruby-1.8.6.tar.gz"
"cd ruby-1.8.6"
"./configure && make && make install"
6. "wget http://rubyforge.org/frs/download.php/17190/rubygems-0.9.2.tgz"
"tar xzvf rubygems-0.9.2.tgz"
"cd rubygems-0.9.2"
"ruby.set.rb"
7. "rm -rf ruby*"

adinov said...

I was scouring the net to try to figure out how to install the latest Octave 3.0.3 in Ubuntu.

These were the two things apparently missing from the Octave installation package.

apt-get install libreadline5 libreadline5-dev

fort77_1.15-7_all.deb


Being a novice, it took me a day to figure all this out. My question is;

Why doesn't the Adept installer simply allow me to get the latest Octave??

Why doesn't Octave ./configure simply tell me where to get the required files?? (or better still, include the files in the installation package!)

Things like this are a huge turnoff for people trying to get into linux. I have been trying for the last 13 years!

redsea501 said...

Nice Topic

I hope you take a look to my blog
http://ebook44free.blogspot.com/

It is about FREE eBooks

Thanks..,

Anonymous said...

greenprogrammer.blogspot.com is very informative. The article is very professionally written. I enjoy reading greenprogrammer.blogspot.com every day.
bad credit loan
canada payday loans