Installing Rails 2 on Ubuntu

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? 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/rails. 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 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 Rails 2 environment. In ~/bin/rails.sh I put:

#!/usr/bin/env bash

RAILS_PREFIX=/opt/rails

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

PS1="[rails] $PS1"

Ruby

I started installing Ruby. Maybe this wasn’t needed, but I wanted a really clean and separated environment (after downloading and unpacking):

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

Time to enter the Rails 2 environment:

$ source ~/bin/rails.sh
[rails] $ which ruby
/opt/rails/bin/ruby
[rails] $ 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 Rails’ console, we also need the readline gem:

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

Gems

Installing rubygems is easy as well, after downloading and unpacking, be sure to be in the rails 2 environment and run:

[rails] $ cd rubygems-0.9.5/
[rails] $ ruby setup.rb
...
Removing old RubyGems RDoc and ri...
Installing rubygems-0.9.5 ri
into /opt/rails//lib/ruby/gems/1.8/doc/rubygems-0.9.5/ri...
Installing rubygems-0.9.5 rdoc
into /opt/rails//lib/ruby/gems/1.8/doc/rubygems-0.9.5/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)...
...done.
No library stubs found.
[rails]  $ which gem
/opt/rails/bin/gem
[rails]  $ gem --version
0.9.5

Good!

Rails

Just as explained on the Rails web site:

[rails]  $ gem install rails
Bulk updating Gem source index for: http://gems.rubyforge.org
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
OpenURI::HTTPError: 404 Not Found reading

http://gems.rubyforge.org/gems/activesupport-2.0.1.gem

Ooops, I’ve got some of those. Just try again:

[rails]  $ gem install rails
Successfully installed actionmailer-2.0.1
Successfully installed activeresource-2.0.1
Successfully installed rails-2.0.1
3 gems installed
Installing ri documentation for actionmailer-2.0.1...
Installing ri documentation for activeresource-2.0.1...
Installing RDoc documentation for actionmailer-2.0.1...
Installing RDoc documentation for activeresource-2.0.1...

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

Update 2007-12-31: include installation of readline.

About these ads

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