Ubuntu 8.04 Rails Server Build Pt 1

Building up a server for Ruby on Rails can be a big pain, especially if you don’t know what you are doing. Here is my build of an Ubuntu server using 8.04 Hardy Heron. You can use this as a guide to build either a server using the server or desktop edition of Ubuntu. It is all command line so it will work either way.

I am not going to cover the actual install of Ubuntu because this is going to be long enough without that. Ubuntu makes their installer very easy but if I get some requests to document the install process I might post it up later.

Once you have Ubuntu 8.04 installed the first thing you are going to want to do is edit your software repository sources list. Open up the command line (because the rest of this will be done using that) and away we go.

First make a backup of the sources.list file so if we screw it up you can revert back:

#: sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

Next edit the file:

#: sudo vi /etc/apt/sources.list

Comment out the line about the cd-rom drive. Uncomment the lines about the universe, backports, and security repositories, Save the file: (vi command -> :wq) and update the repositories packages:

#: sudo apt-get update

Next we are going to install the ssh server. I am only going to mention the things that I configure for ssh but I am not going to discuss why, so once it is installed you should check this out for getting the configuration to work.

Install ssh server:

#: sudo apt-get install ssh

Make a backup of the ssh configuration file:

#: sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup

Edit the ssh configuration file:

#: sudo vi /etc/ssh/sshd_config

Look for the line that says:

# What ports, Ips and protocols we listen for
Port 22

Change the port number to some arbitrary number like 6302, but make sure you remember the port number because you will need it to connect to the server. Look for the line like this:

PasswordAuthentication yes

and change it to no. Don’t do this until after you have verified that you can ssh into your server and it accepts the public key. Save the file. Then restart ssh using the following command:

#: sudo /etc/init.d/ssh restart

Next we are going to install ruby using apt-get. Some might prefer to install a particular version if this is the case look into building it from source. If you just want a working ruby on rails server and don’t care if it is version 1.8.6 then proceed with my instructions.

#: sudo apt-get install ruby irb ri rdoc ruby1.8-dev libzlib-ruby libyaml-ruby libreadline-ruby libncurses-ruby libcurses-ruby libruby libruby-extras build-essential libopenssl-ruby libdbm-ruby libdbi-ruby libxml-ruby libxml2-dev

(Note: that was all one line so don’t add any carriage returns)

Now that ruby is installed we are going to install RubyGems from source and use that to get rails and other things. First we need to download it using wget, I am installing RubyGems version 1.1.1 but you can download any version you want.

#: wget http://rubyforge.org/frs/download.php/35283/rubygems-1.1.1.tgz

Now lets extract and install it:

#: tar -xzf rubygems-1.1.1.tgz
#: cd rubygems-1.1.1
#: sudo ruby setup.rb
#: sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Next we will use Ruby Gem to install Rails:

#: sudo gem install rails

Once that is done we will install Mongrel (used for serving up rails):

#: sudo gem install mongrel
#: sudo gem install mongrel_cluster

Finally install Nginx (our webserver):

#: sudo aptitude install nginx

Alright we have everything installed, now it is time to configure it. But for now I am going to take a break, I know I know it only took 30 minutes to get to this point, but it has taken me hours to make this post so BACK OFF! I promise to post up the configuration for everything soon.

Leave a Comment