Howto install Ruby on Rails on Debian Etch

Using Ruby 1.8.7 from etch backports repository, instead of 1.8.5 that usually comes with etch @author Benny Zaminga [September 2008]

In this howto we will show you how to install Ruby on Rails on a Debian Etch Server. You'll need administrator-privileges and should be familiar with the useage of a shell (bash).

Needed things to successfully run rails:

  • Ruby interpreter since Rails is written in Ruby
  • Ruby on Rails
  • Libraries needed to run Rails
  • MySQL (we're gonna cover MySQL in this howto. Other DB's are supported by Rails)

Connect to your server. In our case, it's a remote machine and we will use SSH to securely connect and do the needed changes. We will login directly as root, since we have that possibility. Maybe you only have a user-account, which is allowed to administer the system or at least install/remove packages. In case you don't have the root login, you'll need to add sudo to almost all these commands described below.

ssh root@your-server.com

Start by installing some pre-requisites, doing:

apt-get install aptitude
aptitude install zlib1g mysql-server mysql-client libmysqlclient15-dev libmysql-ruby -y

Now there's a little caveat here: Debian Etch comes with Ruby1.8.5 by default. Since we need at least Ruby1.8.6, we'll be adding an additional backports repo to our sources for apt. Add this line to your sources.list usually found in /etc/apt/

deb http://www.backports.org/debian etch-backports main contrib non-free

Now import the proper key, else you'll get warnings:

wget -O - http://backports.org/debian/archive.key | apt-key add -

Update your sources:

aptitude update

Install Ruby1.8.7 from backports:

aptitude -t etch-backports install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 libopenssl-ruby -y
aptitude -t etch-backports install irb1.8 libreadline-ruby1.8 libruby1.8 -y

Now we install rubygems from source. To be sure to get the latest version of rubygems visit RubyForge and get the current release.

mkdir src
cd src
wget http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz
tar xvfz rubygems-1.3.0.tgz
cd rubygems-1.3.0
ruby setup.rb
ln -s /usr/bin/gem1.8 /usr/bin/gem

Now we're ready to install rails using gem:

gem install rails

To be sure your ruby on rails will work, do the following:

irb

When irb lauches, enter the following require statement:

require 'mysql'

If that returns true, you're on rails.

Installing sqlite-support for rails

If you want to use the sqlite database in conjunction with rails, you'll need to perform the following steps:

aptitude install sqlite3 libsqlite3-ruby -y

Launching webrick so that it binds to specific IP and port

Now that you have successfully setup rails, you surely want to launch the builtin webserver called WebRick. On certain servers with multiple IP's, this trivial task can turn out to be tricky. WebRick starts, but cannot be reached from outside. The solution is quiet simple. You need to bind WebRick to an IP that is reachable from the outside world. Be sure to use a free port, that's not already in use. To bind WebRick to an external IP using a custom port, use this syntax (without curly braces):

ruby script/server -p {YOUR DESIRED PORT} -b {YOUR DESIRED IP}