infundibulum

Installing Rails (with readline and console support) on Ubuntu LTS

January 27th, 2007

Here’s what I had to do to get Ruby on Rails to run on Ubuntu LTS with a functioning console (and irb).

(By the way, Wordpress has kind of borked up the formatting of this post, there’s a plain version at:

http://ruphus.com/code/rails/railsonubuntu-howto.html

It comes down to:

  1. Random stuff
  2. Ruby (from source)
  3. Mysql packages
  4. Rubygems (from source)
  5. Rails (from a gem)

Building on posts by:

Thanks guys.

Preliminaries

Mostly via Ed Howland’s post (I believe termcap-compat, which he lists, is no longer necessary, since libc is up to 6 or uh erm… well I don’t rightly know, but that package wasn’t in the repos and everything seems to work for me without it! ☻).

sudo apt-get install gcc 
sudo apt-get install build-essential 
sudo apt-get install bison byacc gperf 
sudo apt-get install zlib1g-dev 
sudo apt-get install libreadline5 libreadline5-dev 
sudo apt-get install libncurses5 libncurses5-dev  
sudo apt-get install libssl-dev 

Build Ruby

Download the Ruby source:

wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.5-p12.
tar.gz tar xzf ruby-1.8.5-p12.tar.gz 

And build it. Make some coffee, this takes a while. ☻

cd ruby-1.8.5-p12 ./configure make sudo make install 

Not sure why this is necessary (ActionMailer?)

apt-get install postfix 

You’ll also want Ruby’s documentation stuff:

sudo apt-get install  rdoc ri irb 

Mysql packages

apt-get install mysql-server mysql-common mysql-client libmysqlclient15-dev libmysqlclient15off 
apt-get install libmysql-ruby1.8 

Build Ruby Gems

We’ll be using this to install Rails:

wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz 
tar xzf rubygems-0.9.0.tgz cd rubygems-0.9.0 
sudo ruby setup.rb 

Build Rails

Actually the easiest part, I’ve never had trouble with this (knock wood).

sudo gem install rails --include-dependencies 
sudo gem install mysql 

Note that the mysql gem is really the DB connector for Ruby; it’s not Mysql itself. (We already did that.)

Afterword

Now that I’ve explained what worked for me, let me explain the problem I had, in case you’re interested or facing the same problem.

When I originally followed the steops in Richard Crowley’s post, everything seemed to install fine and Rails worked great.

But I found that my console wouldn’t work, just like Paul Ingles:

Loading development environment.
/usr/local/lib/ruby/1.8/irb/completion.rb:10:in `require':
 no such file to load -- readline (LoadError)     
 from /usr/local/lib/ruby/1.8/irb/completion.rb:10     
 from /usr/local/lib/ruby/1.8/irb/init.rb:252:in `load_modules'     
 from /usr/local/lib/ruby/1.8/irb/init.rb:250:in `load_modules'     
 from /usr/local/lib/ruby/1.8/irb/init.rb:21:in `setup'     
 from /usr/local/lib/ruby/1.8/irb.rb:54:in `start'     
 from /usr/local/bin/irb:13 

This means no readline in irb, and no script/console whatsoever, which I gotta have.

So I tried his solution, which consisted of building readline from source, and then building Ruby. I’m not totally positive (though I’m going to find out soon when I rerun this whole process on my laptop), but I think that the steps I’ve described above obviate building readline from source on Ubuntu.

And now this works! \o/

./script/console 

Leave a comment!

I’d really appreciate comments about this process, especially corrections or simplifications.

I’d also just like to get in touch with other folks running Rails on Ubuntu! Believe it or not not everybody using Rails is on OSX. ;-)

Comments

  1. 1

    I had the same problem with script/console in kubuntu. I thought that your solution was a bit lengthy. So, after further search I found a couple of links that solved the problem in a simpler manner. Check them out:
    http://ubuntuforums.org/showthread.php?t=169891
    http://blog.nanorails.com/articles/2006/03/06/installing-readline-on-kubuntu

    Steps that worked for me:
    1.) Download ruby source.
    Download Here
    2.) Extract the tar file.
    tar -xvf ruby-1.8.5-p12.tar.gz
    3.) Change to that directory
    cd ruby-1.8.5-p12.tar.gz
    4.) Type these commands.
    ./configure
    make
    sudo make install
    5.) Install readline and ncurses.
    apt-get install libncurses5-dev libreadline5-dev
    6.) go back to the folder ruby source folder.
    ruby-1.8.5-p12.tar.gz
    7.) Type these commands
    cd ext
    cd readline
    ruby extconf.rb
    make
    sudo make install

    Thats it. The console bug no longer appears.

    - ror-fan @
  2. 2

    Do you have ruby 1.8 installed twice? “apt-get install ri” etc finds that I don’t have ruby 1.8 package installed (because I have installed 1.8.5 from source) and wants to install it.

    Currently I have severely borked rails 1.2.2 installation (every attempt to use rails apart from -v gives an error “undefined method `write_inheritable_attribute’”) and I’m trying to figure out what went wrong.

    Ruby 1.8.5 in /usr/local seems to be ok. I can install rails/mysql etc gems. This all started when I had an existing ruby 1.8.4 and 1.2.1 rails installation but wanted to upgrade to 1.8.5. Baaaaad move.

    - LadyBug @
  3. 3

    Just a side comment on my problem. It seems that while rails/gems/ruby were installed ok, the rails dependencies were somewhat mangled. So, gem uninstall/install activesupport/activerecord/etc helped a lot.

    At least webrick runs now, but my application still doesn’t.

    - LadyBug @
  4. 4

    Hi peeps,

    I am just pasting some notes I have made that may be helpful! The notes are not complete but my offer a clue or two.

    ————————————————–

    How to install a rails stack on Ubuntu Dapper Drake.

    # This quick guide makes the following assumptions:
    # You are familiar with Ubuntu server and file directories.
    # You are aware of creating users and keys.
    # You are aware of Linux security measures.
    # ‘\’ = part of the previous line (cat).

    1. “Uncomment out unviverse packages. etc/apt/sources.list”

    # When building Ruby and Rubygems from source, some libraries are needed.
    # This is when we use apt-get to install the libraries we need.

    2. “apt-get update”
    3. “apt-get install build-essential”
    4. “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”

    # Alternatively step 4 may be combined, as below:

    “apt-get install bison byacc gperf zlib1g-dev libreadline5 \
    libreadline5-dev libncurses5 libncurses5-dev 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*”

    # We do not include Rails rdoc. This saves production system resources.

    8. “sudo gem install rails –include-dependencies –no-rdoc –no-ri”

    # Now we install MySql

    9. “apt-get install mysql-server-5.0 mysql-client-5.0 \
    libmysqlclient15-dev libmysqlclient15off zlib1g-dev libmysql-ruby1.8″

    # Install the mysql/Ruby binding
    “sudo gem install mysql”

    # make sure you have irb ‘require’ rubygems. The easy way (so far) is
    # create a file ‘.irbrc’ in /etc/.irbrc
    “nano .irbrc”

    # In your .irbrc file put the following –
    “require ‘rubygems”

    - MichaelT @

Leave a Reply