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

Configuring Java on Kubuntu 10.10


2010/12/25 Update: Added the removal of the OpenJDK and added the installation of the browser plugin

Today, I had to, again, scratch my Kubuntu install and install it over again. I wonder what I did wrong this time :s

Anyway, what’s important is that, by default, Kubuntu 10.10 ships with OpenJDK 6. When I develop, I prefer to use Sun JDK. This post details the steps necessary to configure the Sun JDK on a Kubuntu/Ubuntu Maverick.

If you find any mistake, please tell me so that I can fix it quickly.

1. Add the necessary repository

Sun JDK is not available in the package repositories available out of the box. The packages are available from the Canonical Partner Repository that can be added with the following commands:

sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"

It is necessary to reload the configuration afterwards using:

sudo apt-get update

2. Install the necessary packages

Once the package repositories are configured, I can now install the JDK packages with:

sudo apt-get install sun-java6-jdk sun-java6-source sun-java6-jre sun-java6-plugin sun-java6-fonts

You can see that I also install the browser plugin as well as the JRE, which the plugin requires.

3. Set Sun JDK as the default JVM

If I execute:

java -version

That yields on my computer:

version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.1) (6b20-1.9.1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 17.0-b16, mixed mode)

I can change the default JVM by executing:

sudo update-alternatives --config java

This command yields:

There are 2 choices for the alternative java (providing /usr/bin/java).
Selection    Path                                      Priority   Status
------------------------------------------------------------
*0           /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
2            /usr/lib/jvm/java-6-sun/jre/bin/java       63        manual mode

Press enter to keep the current choice[*], or type selection number:

After I entered 2, the following message appeared:

update-alternatives: using /usr/lib/jvm/java-6-sun/jre/bin/java to provide /usr/bin/java (java) in manual mode.

If I execute again:

java -version

It now yields:

java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

Voilà, Sun JDK 6 is the default on my system now.

4. Removing OpenJDK

If you like, you can also completely remove OpenJDK from your computer by running:

sudo apt-get remove openjdk-6-jre openjdk-6-jre-headless openjdk-6-jre-lib

If you now run

sudo update-alternatives --config java

it yields:

There are 1 choices for the alternative java (providing /usr/bin/java).
Selection    Path                                  Priority   Status
------------------------------------------------------------
0            /usr/lib/jvm/java-6-sun/jre/bin/java   63        auto mode*
1            /usr/lib/jvm/java-6-sun/jre/bin/java   63        manual mode

Press enter to keep the current choice[*], or type selection number:

5. Testing your browser plugin

If you want to test that the Java plugin is installed properly, you can surf to http://javatester.org/version.html. You will see something akin to:

6. Set JAVA_HOME

I can now set the JAVA_HOME environment variable to allow applications to find where my JDK is installed. I add the following lines in my .bashrc:

export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$JAVA_HOME/bin:$PATH
%d bloggers like this: