Plasticx Blog

Capable of being shaped or formed

compiling ruby 1.8.5 w/ openssl on Debian (Etch/testing) and FreeBSD in $HOME

Posted by Mike 02/03/2007 at 09:44AM

If you want to have control over the version of ruby that is available in your user space here’s how to build and install it in your $HOME directory. The Debian Way of packaging ruby and gem deviates from the Ruby Way on other Nix platforms. So its better to just do it Your Way so that you have control of which ruby and ruby tools (gem, rake, rails, etc.) is available to your user environment.

This is a way to compile and install ruby 1.8.5 with local dependency on openssl, readline, and openssl on Debian (Etch/testing) 686 in your $HOME directory. The method also works for FreeBSD 4.8-STABLE. (BTW if you have root privilege on your machine and you just want to enable openssl to your already installed ruby make sure the libopenssl-ruby Debian package is installed and ignore the rest of the knowledge presented here.)

In googling around to find out how to do this I noticed that often people would break readline support when adding openssl support building their local ruby. I also wanted to have control over the version of ruby running on a hosting account I have at My host account has ruby 1.8.4 installed on a FreeBSD 4.8-STABLE machine. Some FreeBSD builds of ruby have problems with broken iconv support (needed by the TMail library that is used in parsing email in ActionMailer). The technique I’m about to discuss will show how to deal with that as well.

On pages 35-36 Agile Web Development with Rails section “3.4 Installing on Linux” Dave Thomas also describes building a local copy of ruby in the $HOME directory of accounts he has on Linux. We’ll do that and also build a local gem as well.

First make sure the environment of your shell (in the example here its bash) has $HOME/bin in its path and the system library environment variable set with $HOME/lib . Place these export commands at the end of your $HOME/.bashrc and then source your updated bashrc into the current environment after your changes are saved.

#this is at the end of $HOME/.bashrc
export PATH=$HOME/bin:$PATH
export MAN_PATH=$HOME/man
export LD_LIBRARY_PATH=$HOME/lib:/usr/local/lib:/usr/lib
#the gem portion
export PATH=$HOME/gems/bin:$PATH
export GEM_PATH=$HOME/gems
export GEM_HOME=$HOME/gems

Now source your updated .bashrc into your current environment

. ~/.bashrc

Create a directory called builds in your $HOME (or somewhere that you want to do your builds). Change into that directory and download the ruby, iconv, openssl, and readline sources (check for the latest versions when you do this). Then extract each archive.

mkdir $HOME/builds
cd $HOME/builds
tar xzf readline-5.2.tar.gz
tar xzf openssl-0.9.8d.tar.gz
tar xzf libiconv-1.11.tar.gz
tar xzf ruby-1.8.5.tar.gz
tar xzf rubygems-0.9.0.tgz

Now build each library, then ruby, we’ll install gem later at the end.


cd $HOME/builds/openssl-0.9.8d
./config —prefix=$HOME —openssldir=$HOME/openssl shared
make test
make install

ReadLine Library

cd $HOME/builds/readline-5.2
./configure —prefix=$HOME
make install

Iconv library

cd $HOME/builds/libiconv-1.11
./configure —prefix=$HOME
make install

Ruby for Debian and FreeBSD. I think not having libncurses5-dev installed on the host system will affect the build of readline support. If you don’t have in /usr/lib or /usr/local/lib then you’ll have to build it locally (as with the other libraries) and include it as a —with-ncurses-dir=$HOME parameter to configure. If you don’t see in the ldd output (below) then you’ll have install your own local library.

cd $HOME/builds/ruby-1.8.5
./configure —prefix=$HOME —with-static-linked-ext —with-iconv-dir=$HOME —with-openssl-dir=$HOME —with-readline-dir=$HOME
make test
make install

As you can see the local version of ruby is installed and is using the local openssl, readline, and iconv libraries.

mike@lab ~/builds/ruby-1.8.5$ which ruby
mike@lab ~/builds/ruby-1.8.5$ ruby —version
ruby 1.8.5 (2006-08-25) [i686-linux]
mike@lab ~/builds/ruby-1.8.5$ ldd $HOME/bin/ruby => (0xffffe000) => /lib/tls/i686/cmov/ (0xa7f55000) => /lib/tls/i686/cmov/ (0xa7f26000) => /lib/tls/i686/cmov/ (0xa7f01000) => /home/mike/lib/ (0xa7ed4000) => /usr/lib/ (0xa7e93000) => /home/mike/lib/ (0xa7e59000) => /home/mike/lib/ (0xa7d30000) => /home/mike/lib/ (0xa7c51000) => /lib/tls/i686/cmov/ (0xa7c4d000) => /usr/lib/ (0xa7c39000) => /lib/tls/i686/cmov/ (0xa7b08000)
/lib/ (0xa7f72000)

This is how to set up your local gems.

mkdir $HOME/gems
cd $HOME/builds/rubygems-0.9.0
ruby setup.rb all —prefix=$HOME

Make sure its working

mike@lab ~/builds/rubygems-0.9.0$ gem environment
Rubygems Environment:
VERSION: 0.9.0 (0.9.0)
– /home/mike/gems
mike@lab ~/builds/rubygems-0.9.0$ gem list —local


sources (0.0.1)
This package provides download sources for remote gem installation

Install rails and the rails command will be in your path as $HOME/gems/bin/rails. The include dependencies flag will cause rails, rake, activesupport, activerecord, actionpack, actionmailer, and actionwebservice to be installed.

gem install --remote --rdoc --ri --include-dependencies rails
gem list --local

Run gem_server to view your freshly minted documentation.

Posted in , , , |


Use the following link to trackback from your own site:

  1. Juergen W.
    04/01/2007 at 11:09AM

    Hi Mike,

    Thanks for putting this together – I used your instructions step-by-step with my dreamhost shell account. It worked flawlessly. Great work, thanks so much. This was by far the most useful and precise – yet short – documentation for building and installing RoR yourself. Thanks, Juergen

  2. mrkiss
    04/14/2007 at 08:40AM

    you have mistype in ruby compile command. the new line is omitted ^^
    and the rest of all is perfect
    and I upgraded the ruby and rubygems version. It works perfectly too
    Thank you very much Mike

  3. mikemondragon
    04/18/2007 at 09:17AM

    Fixed, thanks for the kind words and catching the error.

  4. seb
    06/24/2007 at 02:48AM

    Thanks for this. You may want to mention an optional “make install-doc” in the ruby install section to make the ruby documentation available to ri and irb help.

  5. Jordan Curzon
    12/28/2007 at 10:30AM

    On Ubuntu 7.04 I had to add —with-readline=/usr to get rails to work. —with-readline didn’t seem to be enough. I also had to install libreadline5-dev libncurses5-dev

  6. Charles
    12/29/2007 at 10:39AM


    I’m also on Ubuntu and I can’t install gem, I’m also missing libreadline5-dev && libncurses5-dev.

    I’m a Linux newb and I’m trying to follow what you did.
    I’m wondering if the —with-readline=/usr is actually missing the -dir part.

  7. Soup
    01/18/2008 at 07:11AM

    Thank you very much. your stuff is very useful.
    I try to bundle
    ruby 1.9.0
    gem 1.0.1
    rails 2.0.2
    everything is new

  8. Andrew Kirk
    09/30/2010 at 06:57AM

    Thanks so much! This was very helpful.

Web Statistics