Ubuntu - Ruby on Rails

The Ubuntu Intrepid - Setup article covered securing, updating, and personalizing the installation. Now you are ready to add some working software, Ruby on Rails.


Version Update

This article has been updated to use the latest (at the time of writing) version of RubyGems, version 2.2.0, and Ruby on Rails version 4.0.2.

Recommended Installation Method

Although Ruby is available via package management systems the version is usually quite stale. Although doing so might take some time, the best way to ensure that you get the proper versions for Ruby and RubyGems is to compile from source.

Install Ruby and RubyGems

The following packages will enable you to compile Ruby as well as necessities for Rails. Run the following command to download them:

sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev nodejs

To compile Ruby, you need to download the source. The best place to do that is directly from the Ruby-Lang website.


This web page lists all of the stable current versions of Ruby, including the most current stable version. Although this article uses 2.1.0, you can choose 2.0.0 or 1.9.3, both of which compile and install RubyGems in the same way. All versions are compatible with Rails 4.x.

Create a directory for your source and install Ruby as follows:

mkdir src && cd src 
wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.0.tar.gz
tar -xzvf ruby-2.1.0.tar.gz
cd ruby-2.1.0
make && sudo make install

After Ruby is installed, you can check the version by running the following command:

ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]

Because you compiled from source, RubyGems is also installed. Verify its version by running the following command:

gem –v

To ensure that you have the latest version of RubyGems, you can run the following command:

gem update –system

Install Rails

Now that Ruby and RubyGems is installed, you can install the Rails framework.

Run the following command:

sudo gem install rails

This process will take some time and install all of the necessary gems required for Rails to function normally.

After the command has finished running, you can check the Rails version by running the following command:

rails –v
Rails 4.0.2

Create an Application

To create an application, you can simply run the following command:

rails new sampleapp

This command creates all of the necessary files and directory structure inside of a new directory called sampleapp.

Install MySQL

By default, Rails uses SQLite as a database. However, you can also use MySQL when creating a new application.

To install MySQL, you need the MySQL client-dev package, and the Ruby MySQL library in order for the database connector to work. Run the following command:

sudo apt-get install libmysqlclient-dev libmysql-ruby

After the installation is complete, you can create a new application with the MySQL adapter, first by installing the gem, and then by creating the application, as follows:

sudo gem install mysql2
rails new sampleapp –d mysql

Connection details should be specified in the database configuration file, which in this case is the following file (localhost is default):


Install Postfix

Finally, you need to install Postfix so that you can send email from your Rails applications. Run the following command:

sudo apt-get install postfix -y

Answer the Postfix installation questions as you see fit. The defaults usually suffice if you are using it only to send email and not to receive email.


You now have a Ruby on Rails stack set up and ready to use. The next step is to install the server of your choice, whether that be Litespeed, Nginx, or Apache.

© 2015 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER