Ubuntu

To work with RoR we need to install Ruby first.
There a couple of ways to install ruby on an Ubuntu machine: You can install ruby from Ubuntu repository or you can install ruby from source.
Go to console and install the following packages to get basic utilities:
sudo apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev checkinstall

While Ubuntu allows you to install Ruby gems from Debian packages via apt-get or Synaptic, there is a consensus that its not a good idea. Instead get Ruby installed using the Ubuntu (Debian) package ( ver 1.8.7 with 9.04 Ubuntu Server at this writing) and do all the other Rails, Gems, and Ruby-oriented apps using Gems.

1) To install ruby from Ubuntu repository.

 sudo apt-get install ruby 

As usual, if your system advises you to install other packages like ruby-dev, go ahead and get those too.

Once this is done, you can go to Installation of rubygems section and install rubygems and the rest of the Rails apps via Gems.

2) To install ruby from source.

Go to official ruby site http://www.ruby-lang.org and choose between releases (1.8.7, 1.9.1 of 1.9.2). Explore their ftp to see all available packages.
One option is Ruby enterprise edition . It comes with its own installer.
Download package:
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.9.1-p129.tar.gz

Unpack it:
 tar xzf ruby-1.9.1-p129.tar.gz

To install it:
cd ruby-1.9.1-p129/
$ ./configure
$ make
$ sudo checkinstall

Then check options:
0 -  Maintainer: [ root@jxubuntu ]
1 -  Summary: [ Package created with checkinstall 1.6.1 ]
2 -  Name:    [ ruby-1.9.1 ]
3 -  Version: [ p129 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ ruby-1.9.1-p129 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ ruby-1.9.1 ]

Looks ok. Follow instructions on screen to finish installation.
Type command
ruby -v
to see which ruby is on board.
Finally, to check ruby and libraries:
ruby -ropenssl -rzlib -rreadline -e "puts 'Viva Railstutor'"

If the console prints Viva Railstutor then ruby is ready.

Installation of rubygems

If you have chosen ruby 1.9 then you already have rubygems. If not, use this command to install rubygems:
 sudo apt-get install rubygems

Update them to current version with
sudo gem update --system

If you have chosen ruby enterprise edition then follow instructions on screen to have rubygems.
If you couldn't install using the package manager (apt-get), then install rubygems manually: # Download them from rubyforge:
wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
* Unpack
tar xzf rubygems-1.3.5.tgz
* Go into the new folder and install:
cd rubygems-1.3.5/
ruby setup.rb
* Check version
gem -v
* Then update them to make sure you have the current version
sudo gem update --system

Installation of rails gem

To standard way to install a gem with rubygems is with the command
sudo gem install gem_name

So to install rails as gem enter:
sudo gem install rails
it should install (Note, 2.3.3 is the current version as of this writing):
actionmailer (2.3.3)
actionpack (2.3.3)
activerecord (2.3.3)
activeresource (2.3.3)
activesupport (2.3.3)
rails (2.3.3)

Installing the database

When you start new rails project you can define which database to use, like this:
 rails -d mysql new_project_name

If no database is specified, the default is SQLite.
If you use anything other than SQLite, you must edit the database configuration file config/database.yml and provide username and password to access your database.

SQLite

To install SQLite in ubuntu box, enter:
sudo apt-get install sqlite3 libsqlite3-dev

if you installed ruby from ubuntu repository add package libsqlite-ruby.
Then install gem to allow ruby work with SQLite:
sudo gem install sqlite3-ruby

MySQL

To install MySQL enter:
sudo apt-get install mysql-server mysql-client mysql-gui-tools-common libmysqlclient16 libmysqlclient16-dev

The mysql-gui-tools-common package provides gui tools to work with MySQL. You don't need it on a production server.
if you installed ruby from ubuntu repository add package libmysql-ruby.
Then install mysql gem:
sudo gem install mysql

PostgreSQL

To install PostgreSQL on you machine enter:
sudo apt-get install postgresql-client postgresql-8.4 postgresql-server-dev-8.4

If you want to have a gui program to work with database install package pgadmin3.
Install pg gem to allow ruby to work with PostgreSQL database:
sudo gem install pg

IDEs and Texteditors

There are full-blown IDEs with RoR support:
NetBeans, Eclipse, Aptana, and Aptana RadRails.
Texteditors are much more lightweight and provide functions and syntax highlighting to work with RoR.

Gedit

Gedit itself doesn't contain features to work with with RoR. But with pack of plugins - Gmate you get code highlighting, snippets, themes, etc.

Vim

If you install all from ubuntu repository, then install vim from repository too:
sudo apt-get install vim-full

If you installed ruby from source, then you can install vim from source too: # Find a good mirror for you Vim mirrors and then:
wget http://mirror.hostfuss.com/pub/vim/unix/vim-7.2.tar.bz2
# Unpack and install vim:
tar xjvf vim-7.2.tar.bz2
cd vim72/
./configure
make
sudo checkinstall
# Checking vim: type vim --version and output should be something like:
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Aug  5 2009 18:03:01)
Compiled by jastix@jxubuntu

with a lot of lines after. # Making vim and ide for RoR: * long way: search and install plugins one by one. * faster way: download and install complete config . Don't forget to install ACK:
sudo apt-get install ack
# Now you can start vim by typing gvim in console and learn how to use it.

KDevelop

KDevelop is a GUI editor with the usual syntax highlighting and support for Ruby and many other languages. It's available if you have installed the KDE desktop ( even if you are using Gnome). It supports remote SSH shares well, and search/replace through multiple files somewhat.

Webservers

Rails works with several webservers, and even installs with a default lightweight one called WEBrick, which should work right after the basic installation. The Rails community has evolved some scalable systems for deployment (outside the industry-standard Apache webserver world) and there is some documentation for these at:
  1. Deploying Ruby on Rails is Easy
  2. Deployment Stacks

Testing using WEBrick

Once you've set up your Rails app, start WEBrick.

cd <topmost directory of your application>
script/server  

You should see something like this Redmine setup:

 => Booting WEBrick...
GLoc v1.1 running in development mode. Strings can be modified at runtime.
=> Rails 2.1.2 application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2009-10-29 11:14:57] INFO  WEBrick 1.3.1
[2009-10-29 11:14:57] INFO  ruby 1.8.7 (2008-08-11) [i486-linux]
[2009-10-29 11:14:57] INFO  WEBrick::HTTPServer#start: pid=2915 port=3000

To try it out, use http://<your host or localhost>:3000

Using Apache2

Now you won't likely be deploying on WEBrick, and if you choose Apache2 as your deployment webserver, you have several choices. Large-scale deployment is outside the scope of this doc, but there are two essential decision points which do apply to any Apache2 Rails deployment:
1) do you have a dedicated server or a server with other apps running?
2) do you use Mongrel/Thin/Nginx or Passenger?

Apache2... dedicated or multi-app server?

The problem is that Rails demands to be in the document root of your server. If you need multiple document roots, for instance one for rails and one for everything else, then you'll probably want to create virtual hosts, which requires some control over DNS services at your network. See the extensive Apache documentation and there is one Ubuntu example here:

  1. An Alternate Apache Configuration with a named vhost Ubuntu 9.04

Otherwise if Rails owns the server, you can just give it the document root. You set this up in the Apache2 configuration files in /etc/apache2.

Apache2...Mongrel-etc. or Passenger?

The choice here is beyond the scope of this document, and there are several combinations to choose from. For a start see:

  1. Rails Wiki Deployment Stacks

However Passenger is a newer implementation and may work better for you. It's sometimes called "mod_rails" because its a loadable module for Apache like mod_perl and mod_php. Unlike mod_php, Passenger is quite sensitive to installation. Read the documentation carefully:

  1. Passenger
  2. Passenger on Apache
here is one type of Passenger configuration using a vhost:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    ServerName app.example.com
    DocumentRoot /var/www/redmine/public/
    PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5
       PassengerRuby /usr/bin/ruby1.8
    RailsEnv development 
        <Directory "/var/www/redmine/public/">
        Options Indexes +ExecCGI FollowSymLinks 
               #AddHandler fcgid-script .fcgi
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>

Tips

  • when installing ruby enterprise edition its installer will ask you for folder. Default is /opt/ruby-enterprise-version (for ruby-enterprise-1.8.6-20090610 it will be /opt/ruby-enterprise-1.8.6-20090610). Change to something shorter, for example, /opt/rubyee. With this you won't have pain when updating.
  • Good recipe for work and experiments: install ruby enterprise edition in /opt and install another ruby in default folder (/usr). See resources 1 and 2 to see a way to switch between them.
  • Gems can be updated with command
    sudo gem update
  • List of installed gems available with
    sudo gem list

Additional resources

  1. Ubuntu documentation RubyOnRails
  2. Installing ruby 1.8 and 1.9
  3. Ruby switcher
  4. Ubuntu docs: PostgreSQL
  5. Using Vim as RoR IDE

Also available in: HTML TXT