Installation of a RoR setup on Debian / Ubuntu for beginner coders
Here are some installation instructions for installing a Ruby development environment on a Debian or Ubuntu computer. It’s targeted at people who have never tried programming before or installed a computer language, but who are ok with firing up a terminal and installing stuff. While there are lots of programming tutorials on the web, there aren’t very many available for people who don’t know what the hell they’re doing but want to try web programming.
Why Ruby?
Any time you want to make a website that does more than display HTML files, i.e. a website which can do calculations or store information in a database for later retrieval, you need to write it using a computer language. There are lots of languages that can do this (including Java, PHP, Python, Perl, and many others). My favourite is Ruby, primarily because it’s easy to understand and lends itself to simple, clean, pretty code. It’s fairly easy to install, and it’s also a Free Software language, which is politically important if people want to be able to retain democratic control over their own information infrastructure. If you want to try Ruby without installing anything on your computer, you can go to Try Ruby and see what you think of it. Type help on the command line to start the tutorial there. It takes about half an hour. If you want to take my word for it that Ruby is A Good Thing™ and just want to take a crack at making a website with it, this tutorial should help you get it set up.
Before you start, you should make sure that your system’s package definitions are up-to-date. To do so, run this command in a terminal:
sudo apt-get update
Step 1: Install a Ruby interpreter
If you want to build a site in Ruby, you need to install the Ruby language. Here’s how to install it on your machine if you’re running Debian or Ubuntu. Note: some of the commands you’ll be asked to type into the terminal are pretty long and annoying, you should be able to just copy and paste them into the terminal by selecting the green text below, copying it, and then pasting it into the terminal using ctrl-shift-v.
sudo apt-get install ruby rdoc1.8 ri1.8 irb1.8 irb ruby1.8-dev
Type or copy/paste that into the terminal and hit the enter key. The terminal will ask you to confirm that you really want to install stuff. Type Y and hit enter to install the packages.
On a Blag system (based on Fedora), ruby`.8-dev was provided by the package ruby-devel.
When this command completes, type
ruby -v
in your terminal to see that it’s installed. The terminal should say something back like:
ruby 1.8.5 (2006-08-25) [i486-linux]
The version number may be different, don’t worry about that.
Ruby will take care of all of the “thinking” aspects of the website, deciding what to show and how to respond to what the user is asking for.
Step 2: Install build tools.
Ruby runs its own packages, called gems, which sometimes need to be compiled as they’re written in a computer language called C. Ruby is a pretty slow language, and C is a really fast language in terms of how fast the computer can crank through the instructions you give it. Without getting too deeply into technical details, the C language needs a program called a compiler to turn any code that a programmer writes into a bunch of 1s and 0s that a computer understands. Luckily with Ruby (which is an interpreted language, not a compiled language, we don’t need to actually compile anything ourselves. However for some stuff, Ruby is too slow, so people write super-fast extensions to Ruby in C.
Don’t let any of that bother you too much at the moment, just take our word for it that you need a C compiler. To install one, type this command into the terminal:
sudo apt-get install build-essential
Step 3: Install the gem package manager
Ruby gems are little chunks of Ruby code which are packaged up into an easy to install format. They provide extra functionality for you to use when writing programs so that you don’t need to re-invent the wheel all the time.
We need to install a bunch of gems so that we can build websites with a system called Rails, so first we need to install the ruby gems package manager. It’s not too tough, do this.;
a) Download the tarball by typing the following command into the terminal:
cd
wget http://rubyforge.org/frs/download.php/17190/rubygems-0.9.2.tgz
b) Extract it by typing the following into the terminal:
tar -xvzf rubygems-0.9.2.tgz
c) Install the gem package manager by typing the following commands, one at a time, into the terminal:
cd rubygems-0.9.2
sudo ruby setup.rb
This will result in a whole pile of stuff showing up in the terminal, probably ending with:
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.
That’s normal, programmers love putting all kinds of cryptic, scary looking notices into programs even when they worked ok. Pretty soon you’ll be able to do it too.
cd
You can test that everything worked by typing
gem -v
into the terminal. It should come back with 0.9.2. Now you can install gems.
Note: When installing gems in any of the steps below, if you are asked which version of a gem you’d like to install, just pick the one with the highest version number which doesn’t say win32 (the win32 gems are for Windows computers) . Also, accept any gem dependencies that the package manager asks you about by typing Y and hitting enter.
Step 4: Install Rails
Rails is basically a pile of Ruby code packaged up as a bunch of gems. It’s an example of what’s called a “web development framework.” Whenever somebody makes a website which is dynamic (i.e. one that involves a language like Java, PHP, Python, Perl, Ruby, etc.) there are a whole bunch of boring, repetitive tasks that the programmer needs to deal with – stuff like accessing the database, submitting form information, checking to see that the user typed in a title for the blog article that they’re making. Stuff like that. Rails is a framework that takes care a lot of the boring crappy jobs and allows us to focus on the important stuff, like how our website should work for users.
To install Rails type this in a terminal:
sudo gem install rails --include-dependencies
Don’t get freaked out if the server comes back and says it can’t find Rails – due to the immense and increasing popularity of Rails, sometimes the server that provides the download is overwhelmed by load (they’re not running on super-fast hardware). Just type the command again if it screws up the first time. Also, it can take a long time for this command to finish, if it seems to be taking a while that’s normal.
Step 5: Install a database server
Back in the olden days, a lot of websites were just HTML files served by a webserver. People would just fire up a text editor, write up an HTML file, and put it on a computer that had access to the web, and that was it. You could still do this, just by typing something like this into a text file:
<html>
<head></head>
<body>When playing rock paper scissors, if you had scissors that were made of rock, you could never lose.</body>
</html>
If you saved that in a text file and opened it by firing up Firefox and saying “file—> open” and selecting the file, it’d show up in your browser.
This approach sucked for a lot of reasons, and didn’t allow much interaction between the user and the site. These days, websites are still shown using HTML in a browser, but instead of us writing all of the HTML by hand like that, we use computer languages (like Ruby) to write some of the HTML for us (Rails basically helps this process out by making it easier to write a Ruby program which writes HTML).
In addition, most websites today store data for later use – Indymedia does this, Google does it, everybody’s doing it. And you should be doing it too. So, you need what’s called a database server running on your machine. Let’s install one of the most popular Free Software database servers, which is called MySql. This program basically holds any stored data we want it to, like the text of a blog article, the list of users who can access a site, etc.
sudo apt-get install mysql-server
Step 6: Install a Ruby database adapter
This allows Ruby and Mysql to talk to each other:
sudo apt-get install libmysql-ruby
sudo apt-get install libmysqlclient15off libmysqlclient15-dev
Note: the version numbers for libmysqlclient15 may be different, if you get a “package not found” or something like that, do a search for the correct package name by typing this into the terminal:
apt-cache search libmysqlclient
Then install whatever comes back using apt-get (as in the libmysqlclient15 line above).
You may find that you try to install mysqlclient, it doesn’t work, and apt-cache search mysqlclient gives back a list of results like this:
libmysqlclient10 - LGPL-licensed client library for MySQL databases
libmysqlclient10-dev - LGPL-licensed client development files for MySQL databases
libmysqlclient12 - mysql database client library
libmysqlclient12-dev - mysql database development files
libmysqlclient14 - mysql database client library
libmysqlclient14-dev - mysql database development files
libmysqlclient15-dev - mysql database development files
libmysqlclient15off - mysql database client library
In this case you can install any two that have matching numbers – e.g. this should work:
sudo apt-get install libmysqlclient14 libmysqlclient14-dev
Using libmysqlclient15off and libmysqlclient-dev should work as well.
Step 7: Install the gem for MySql so that Rails can talk to it
This should be pretty easy:
sudo gem install mysql
You’ll be presented with a list of versions of the gem that it is possible to install. To select one, type the number of the one you want, like 3 without a period, and hit enter. Pick the highest version number that doesn’t have win32 in it. Once the gem code is downloaded, the gem will be compiled using the C compiler you installed in Step 2 – database access is something that should happen really quickly, so the mysql gem is written in C.
Step 8: Install a graphical admin client for MySql
Database administration is often done through the command line, which is a very flexible way to do things but is not real friendly from a “this is my first time making a website” standpoint. To ease the pain, you can optionally install the MySql Administrator:
sudo apt-get install mysql-admin
This gets us a nice graphical interface that we can use to create databases.
Step 9: Make your first Rails website
Ok, by now you’re extremely bitter about sitting around for so long and downloading all of this crap and seeing no results. Let’s get rolling and have you make a quick website.
The first thing you need to do is create a database for it. If you installed the mysql-admin graphical database manager in Step 8, you should be able to use that by going to Applications -> Programming -> Mysql Administrator (if you’re using Ubuntu). In other kinds of Linux, like Kubuntu, Xubuntu, or Debian Etch, it might be under a different menu item, but it’s in there somewhere. So, start it.
It’ll ask you to log into your database server. You can log into it like this:

For hostname, enter localhost. For user, enter root, and leave the password blank, and hit connect. Don’t get freaked by the root user you’re entering without a password, this refers to the root user for the database server rather than for your computer. The default is for Ubuntu to set up Mysql with a root but no password, which is fine for a development machine because (again by default) nobody can connect to the database server from a network unless you specifically allow this. So, you haven’t just opened up some massive security hole in your machine. However, it can be a good idea to set a root user for MySql if you ever intend to (even temporarily) server websites from your machine.
Once you’re logged in, you can create a database. Click on the catalogs button on the bottom left side.

Then right-click with your mouse on the list of available databases and say create schema. Call it smashthestate_development and say Ok. You just created your first database. Unless you’ve created one before, in which case you haven’t.
Now that we have a (blank) database, we can go ahead and create our first Rails application.
We’ll make a new Rails website by opening a terminal and typing
rails smashthestate
A whole bunch of stuff should happen at this point. A directory called smashthestate will be created. Inside that folder is a big pile of Ruby code which forms the basis of your new website. The directory structure will look something like this:

At this point, you should go into the new directory by typing this in the terminal:
cd smashthestate
which gets you into the directory you just created (cd stands for change directory).
Type this to start your Rails webserver:
script/server
Then click this link: visit your new Rails website
This will display the Rails welcome page to let you know everything is working. We don’t have a website that actually does anything yet, though. We will get into a basic Rails programming tutorial in the next installment in this series, but for now, just go back to the terminal where the server is running and type ctrl-c to stop the server while we crank out a new application.
Type this into a terminal while you’re in the smashthestate directory:
script/generate scaffold_resource Article body:text title:string
rake db:migrate
That’ll generate a blog application for you. Start the web server again by issuing this command againin the terminal:
script/server
At this point, you should be able to add blog posts through an administrative website at http://localhost:3000/articles.
