Playing with Ruby

This is a remake of Installing Rails 2 on Ubuntu but targeting Ruby in general and with some improvements. Essentially the same, actually, but more usable, at least for myself.

Ubuntu, like many other free operating systems, have a beautiful package management system that will track what depends on what, what is installed, what is not, what is not longer needed, which versions of each. If you tamper with it, you are asking for trouble. If you do a manual upgrade, from sources, eventually a package upgrade will downgrade your version or some other application being incompatible will not work. And once you start throwing files in /usr, you start to ask for trouble. I’ve been using this type of operating systems for years and I’ve learned this by experience.

Nevertheless you, as I, want to try and code with Rails 2, right? Or Merb? or any other Ruby softawer that hasen’t been packaged yet. Well, this is how I installed it in my Kubuntu box (should work the same for any Ubuntu and Debian derivate as well as others). I’ve decided to install everything on /opt/ruby. I like to keep more-or-less self-contained directories in /opt. So I started with:

$ sudo mkdir /opt/rails
$ sudo chown pupeno:pupeno /opt/rails

and that’s the last time I’ll ever use root access in this document, and that’s the way I like it. Another important detail is that I’ll keep all the environment and software entirely optional. All you’ll do here will be in a separate directory and will not interfere with the rest of your computer. Actually, to use it, you’ll have to load a file, which means, you control when you are entering the Ruby environment. In ~/bin/ I put:

#!/usr/bin/env bash


export PATH="$RUBY_PREFIX/bin:$RUBY_PREFIX/lib/ruby/gems/1.8/bin/:$PATH"
export MANPATH="$RUBY_PREFIX/share/man:$MANPATH"

PS1="[ruby] $PS1"


I started by installing Ruby itself. Maybe this wasn’t needed being that Ruby 1.8 is already available as a package, but I wanted a really clean and separated environment. I started downloading and unpacking ruby-1.8.6-p111.tar.gz:

$ wget
$ tar xvfz ruby-1.8.6-p111.tar.gz

and then the usual compile and installing (look ma! no root, no su, no sudo!):

$ cd ruby-1.8.6-p111/
$ ./configure --prefix=/opt/ruby/
$ make
$ make install

Time to enter the Ruby environment:

$ source ~/bin/
[ruby] $ which ruby
[ruby] $ ruby --version
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]

Good! To have a nice irb and actually be able to run the Rails’ console, we also need the readline gem:

[ruby] $ cd ext/readline
[ruby] $ ruby extconf.rb
[ruby] $ make
[ruby] $ make install


Installing rubygems is easy as well. We again start downloading and unpacking, this time, rubygems-1.0.1.tgz.

[ruby] $ wget
[ruby] $ tar xvfz rubygems-1.0.1.tgz

And now build and install:

[ruby] $ cd rubygems-1.0.1
[ruby] $ ruby setup.rb
Removing old RubyGems RDoc and ri...
Installing rubygems-1.0.1 ri into /opt/ruby//lib/ruby/gems/1.8/doc/rubygems-1.0.1/ri...
Installing rubygems-1.0.1 rdoc into /opt/ruby//lib/ruby/gems/1.8/doc/rubygems-1.0.1/rdoc...
As of RubyGems 0.8.0, library stubs are no longer needed.
Searching $LOAD_PATH for stubs to optionally delete (may take a while)...
No library stubs found.
[ruby]  $ which gem
[ruby]  $ gem --version


Rails and Merb

Just as explained on the Rails web site:

[ruby]  $ gem install rails

or for Merb:

[ruby]  $ gem install merb

And that’s it, you are ready to rail! or merb! (as you can see, all the magic is in that little file)

Leave a Reply

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

You are commenting using your 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