Version 5 (modified by joshuadf, 9 years ago) (diff)


Setup of RubyOnRails? for Ubuntu

This procedure describes a generic setup of the RubyOnRails? environment. After applying these steps, you should be able to instantiate a simple Rails application that uses the local MySQL database for ActiveRecord? storage and serves up a web site on port 3000.

At many points in this procedure, specific versions of packages are explicitly requested during installation. Because feature support can change significantly between releases of Ruby and its Gems, I believe this to be good practice.


  • OS version is Ubuntu 8.10 server.
  • MySQL version 5.0.67 is installed and running on localhost.
  • No Ruby or Rubygems components are currently installed.
  • Unless otherwise noted, all steps are carried out as user 'root'.

Install Ruby Interpreter and Documentation

apt-get install ruby1.8 irb1.8 rdoc1.8 ruby irb rdoc

Install (and update) Rubygems package management

apt-get install rubygems1.8 rubygems
gem install rubygems-update

Install the required Gems

Install Rails.

gem install -v=2.2.2 rails

Install MySQL support:

apt-get install ruby1.8-dev
apt-get install libopenssl-ruby1.8 libopenssl-ruby
gem install -v=2.7 mysql

Install optional libraries

Add 3rd-party gems needed to build and run your application.

gem install -v=2.0.14 authlogic
gem install -v= ruby-ole
gem install -v= spreadsheet

Add a remote gems repository to the package manager, then download and install a module.

gem sources -a
gem install mislav-will_paginate

Create and Run a test application

Create a project called testapp that has MySQL support enabled by default.

rails -d mysql testapp
cd testapp

Edit the database configuration in database.yml.

vi config/database.yml

In order to create a new database called 'testapp_development', specify a user and password in database.yml for connecting to the local MySQL instance. In order to create the database using rake (later in this procedure), you will need to specify a user here that has sufficient privileges (e.g. root). In practice, you should create the database ahead of time and grant CRUD privileges to a user other than root.

  adapter: mysql
  encoding: utf8
  database: testapp_development
  pool: 5
  username: root
  password: *******
  socket: /var/run/mysqld/mysqld.sock

Set the RAILS_ENV variable to 'development' and create the database.

export RAILS_ENV=development
rake db:create

Build a simple scaffolding containing one model type (Movie) and migrate the database.

ruby script/generate scaffold Movie title:string description:text
rake db:migrate

Launch the web server, then browse to http://localhost:3000/movies where you should see a list of movies (initially empty).

ruby script/server