How To Install Ruby on Rails Ubuntu Server 11.10

Ruby Rails is a Web application framework created in 2004 intended as a rapid development web framework. It was intended to emphasize Convention over Configuration (CoC) meaning the developer only needs to specify unconventional aspects of the application. For example, if there is a class Sale in the model, the corresponding table in the database is called sales by default. It is only if one deviates from this convention, such as calling the table “products sold”, that the developer needs to write code regarding these names. It has also been designed around the “Don’t repeat yourself” principle. Both of these ways of thinking allow you, with Ruby Rails, to create excellent, dynamic websites very quickly. So to get started we need to setup a Ruby Rails development server on Ubuntu (Ubuntu 11.04, Ubuntu 11.10)

In this tutorial we are going to go through an install of Ruby Rails on Ubuntu 11.10 using Ruby 1.8. This will work on previous Ubuntu versions however Ubuntu 11.10 is the version I tested this walk-through.

Before we go anywhere we need to install and setup a MySQL server as Ruby Rails requires a database to function correctly, to do this open your terminal and type:

sudo apt-get install mysql-server

when prompted enter the root password for your database server, remember this as you’ll need it later.

Once your MySQL database is installed we need to install the Ruby language. The Ruby language is the programing that Ruby Rails runs on. Ruby itself was designed before Ruby Rails as a dynamic, reflective, general-purpose object-oriented programming language. It was inspired by Perl with Smalltalk-like features. I strongly recommend you learn to make a few programs in ruby before moving onto working work ruby rails, a great free e-book to teach you Ruby can be found here. There are also a few other programs that are needed to run Ruby Rails, these will all be installed in this step so it may take a while:

sudo apt-get install ruby ruby-full libzlib-ruby rvm rdoc irb make sqlite3 libmysql-ruby libmysqlclient-dev nodejs

Now we need to install Gem, this is a little like “Apt-get” or “Aptitude” however it’s designed just to download modules for Ruby & Ruby Rails. Personly I’ve had problems when installing Gem on Ubuntu using apt-get so for this tutoiral we’ll install using the Ruby file downloaded frm the website.

cd ~
tar -xf rubygems-1.8.11.tgz
cd rubygems-1.8.11
sudo ruby setup.rb

Once gem is installed we need to use it to download a few packages (or Gems),

sudo gem1.8 install mysql2 -v '0.3.10'

Once this is downloaded and installed by Gem its time to download and install Rails itself. Installing Rails from Gem can take a while and on my install it always appears to hang for a while. If this happens to you don’t worry it is doing its job, just wait a few more minutes.

sudo gem1.8 install rails

Now its time to setup a new site, the following step will create the site new_rails, feel free to change this to what you like for the remainder of this tutorial,

rails new new_rails -d mysql 

Once this completed your ready to setup your database, todo this open your mysql client with

mysql -u root -p

and create the database for youe app (here we use [APPNAME]_development, you should subsituite your app name in the APPNAME section)

CREATE DATABASE new_rails_development;

Now you can exit your mysql client with the “Exit” command. Now you’ll need to enter your MySQL database password into the rails config. You do this by editing a config file saved in the config directory of your new site,

nano ~/new_rails/config/database.yml

Once you have this file open you’ll need to fill in the password fields with your database password, you only need to do this for the password field (i.e the development DB).

Now its time to start your Ruby Rails Server,

cd new_rails
sudo rails server

you should see something that looks like this:

Now that your server is running go to your web browser and enter the address

http://[YOUR IP]:3000/

If your development server is setup correclty then you should see the folowing window:

If you see this screen then you’ve setup your Ruby Rails development server on Ubuntu 11.04. There are many more steps required in building a website using ruby rails, these are all out of the scope of this tutorial, however you can find a great starting guide here, just scroll down to Step 4 to start where we have left off.

If you have any problems or comments please feel free to leave them in the comments section and I’ll try and get back to you asap.

When I was setting up this tutorial I ran into several problems with Ubuntu and Ruby Rails, these were the following error messages:

An error occured while installing mysql2 (0.3.10)
An error occured while installing sqlite3 (1.3.4)

If have tried installing Ruby Rails on Ubuntu then start again following the above steps in order and you won’t have these problems. However if cant be botherd to install Ruby On Rails again then running the following commands should fix the problem:

sudo apt-get install ruby ruby-full libzlib-ruby rdoc irb make sqlite3 libmysql-ruby libmysqlclient-dev nodejs
rails new new_rails -d mysql

, , , , , , , , , , , , ,

Comments are closed.