Installing Ruby 1.9.2 from the Source on Kubuntu or Ubuntu 10.10


I’m starting to learn Ruby. Therefore, I first need to install it on my Kubuntu 10.10 machine. Because I want to use the most current stable version, I’ll install it directly from the source code.

Installing from the code means downloading the source, building it and installing it. Here are the steps to install the latest stable version at the time of this post (version 1.9.2.p180). I only use the terminal to perform all operations.

This procedure works as well on Ubuntu 10.10.

Create a temporary folder

Let’s create a temporary folder in  ~/temp and work in that directory.

mkdir ~/temp ~/temp/ruby
cd ~temp/ruby

Download the source code

The source code for version 1.9.2.p180 is available at ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p180.tar.gz

Let’s download it using wget.

wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p180.tar.gz

You will see the terminal display something akin to

--2011-03-10 17:38:09--  ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p180.tar.gz
           => `ruby-1.9.2-p180.tar.gz'
Resolving ftp.ruby-lang.org... 221.186.184.68
Connecting to ftp.ruby-lang.org|221.186.184.68|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /pub/ruby/1.9 ... done.
==> SIZE ruby-1.9.2-p180.tar.gz ... 11158935
==> PASV ... done.    ==> RETR ruby-1.9.2-p180.tar.gz ... done.
Length: 11158935 (11M) (unauthoritative)

100%[==============================================================================================================================>] 11,158,935   948K/s   in 14s

The last line tells you that the download was successful.

Unpack the source code

Now that we’ve got the source code, we need to unpack it using the tar command:

tar -xvf ruby-1.9.2-p180.tar.gz

The execution of the command created a folder named ruby-1.9.2-p180. So let’s change to that directory:

cd ruby-1.9.2-p180

Install the libraries necessary to build the software

If we don’t install the necessary libraries, we will run into the following error for example:

 configure: error: in `/home/stephan/Temp/ruby/ruby-1.9.2-p180':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more detail

Let’s install the necessary libraries:

sudo apt-get install build-essential zlib1g zlib1g-dev

Generate config.h and Makefile

To build from the source code, we first need to prepare the configuration for make:

./configure

The execution of the command ends up with lines along the lines of the following:

.ext/include/x86_64-linux/ruby/config.h updated
ruby library version = 1.9.1
configure: creating ./config.status
config.status: creating Makefile

Run make

Let’s now run make.

make

The execution of the command ends up with lines along the lines of the following:

Generating RI...

Files:       515
Classes:    1087 (  654 undocumented)
Constants:  1364 ( 1141 undocumented)
Modules:     239 (  137 undocumented)
Methods:    7642 ( 2876 undocumented)
 53.46% documented

Elapsed: 54.8s

Run make test [Optional]

This optional test allow testing that the make went ok.

make test

The execution of the command ends up with lines along the lines of the following:

PASS all 934 tests
./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb  ./tool/runruby.rb --extout=.ext  -- "./bootstraptest/runner.rb" --ruby="ruby"  ./KNOWNBUGS.rb
2011-02-28 17:02:15 +0100
Driver is ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
Target is ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]

KNOWNBUGS.rb .
PASS all 1 tests

Run make install

To install Ruby, one must be a super user. We will thus sudo the command.

sudo make install

The execution of the command ends up with lines along the lines of the following:

installing binary commands:   /usr/local/bin
installing base libraries:    /usr/local/lib
installing arch files:        /usr/local/lib/ruby/1.9.1/x86_64-linux
installing extension objects: /usr/local/lib/ruby/1.9.1/x86_64-linux
installing extension objects: /usr/local/lib/ruby/site_ruby/1.9.1/x86_64-linux
installing extension objects: /usr/local/lib/ruby/vendor_ruby/1.9.1/x86_64-linux
installing extension headers: /usr/local/include/ruby-1.9.1/x86_64-linux
installing extension scripts: /usr/local/lib/ruby/1.9.1
installing extension scripts: /usr/local/lib/ruby/site_ruby/1.9.1
installing extension scripts: /usr/local/lib/ruby/vendor_ruby/1.9.1
installing extension headers: /usr/local/include/ruby-1.9.1/ruby
installing rdoc:              /usr/local/share/ri/1.9.1/system
installing capi-docs:         /usr/local/share/doc/ruby
installing command scripts:   /usr/local/bin
installing library scripts:   /usr/local/lib/ruby/1.9.1
installing common headers:    /usr/local/include/ruby-1.9.1
installing manpages:          /usr/local/share/man/man1
installing default gems:      /usr/local/lib/ruby/gems/1.9.1 (cache, doc, gems, specifications)
                              rake 0.8.7
                              rdoc 2.5.8
                              minitest 1.6.0

Verify the installation

To verify the installation, let’s check the version of Ruby and RubyGems.

ruby --version

Will yield on my computer:

ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]

And

gem --version

Will yield

1.3.7

Update RubyGems

The current version of RubyGems at the moment of writing this post is 1.5.3. Let’s now update it:

sudo gem update --system

This command will yield:

Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.5.3
Updating RubyGems to 1.5.3
Installing RubyGems 1.5.3
RubyGems 1.5.3 installed

=== 1.5.3 / 2011-02-26

NOTE:  RubyGems 1.5.0 and 1.5.1 have a broken <tt>gem update --system</tt>.

To upgrade you'll need to use the manual upgrade recipe.  Using sudo/su as
appropriate:

  $ gem install rubygems-update
  $ update_rubygems

Bug Fixes:

* Fix for a bug in Syck which causes install failures for gems packaged with
  Psych.  Bug #28965 by Aaron Patterson.

------------------------------------------------------------------------------

RubyGems installed the following executables:
        /usr/local/bin/gem

Let’s now check the new version:

gem --version

Will yield

1.5.3

Clean up

We can now remove the temporary folder:

cd ~
rm -fr temp
Advertisements

One Response to Installing Ruby 1.9.2 from the Source on Kubuntu or Ubuntu 10.10

  1. Alex Bush says:

    Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: