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=" $PS1"
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 $ which ruby /opt/rails/bin/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 Rails’ console, we also need the readline gem:
# cd ext/readline # ruby extconf.rb # make # make install
Installing rubygems is easy as well, after downloading and unpacking, be sure to be in the rails 2 environment and run:
$ cd rubygems-0.9.5/ $ 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. $ which gem /opt/rails/bin/gem $ gem --version 0.9.5
Just as explained on the Rails web site:
$ 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:
$ 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.