Ruby on Rails on Ubuntu 12.04 LTS

About Ruby on Rails


Ruby on Rails is an application stack that provides developers with a framework to quickly create a variety of web applications.

Ruby on Rails does take a little while to install on a virtual server, but luckily there are a lot of helpful tools to make this process as easy as possible.

You can run this tutorial on your droplet as a user with sudo privileges. You can check out how to set that up here: Ubuntu Server Setup

Step One— Install Ruby with RVM


Before we do anything else, we should run a quick update to make sure that all of the packages we download to our VPS are up to date:

sudo apt-get update

Once that’s done, we can start installing RVM, Ruby Version Manager. This is a great program that lets you use several versions of Ruby on one server; however, in this case, we will just use it to install the latest version of Ruby on the droplet.

If you do not have curl on your system, you can start by installing it:

sudo apt-get install curl

To install RVM, open terminal and type in this command:

curl -L get.rvm.io | bash -s stable

After it is done installing, load RVM.

source ~/.rvm/scripts/rvm

In order to work, RVM has some of its own dependancies that need to be installed. You can see what these are:

rvm requirements

In the text that RVM shows you, look for this paragraph.

Additional Dependencies:
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
  ruby: /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

Just follow the instructions to get your system up to date with all of the required dependancies.

rvmsudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

Step Two—Install Ruby


Once you are using RVM, installing Ruby is easy.

rvm install 1.9.3

Ruby is now installed. However, since we accessed it through a program that has a variety of Ruby versions, we need to tell the system to use 1.9.3 by default.

rvm use 1.9.3 --default

Step Three—Install RubyGems


The next step makes sure that we have all the required components of Ruby on Rails. We can continue to use RVM to install gems; type this line into terminal.

 rvm rubygems current

Step Four—Install Rails


Once everything is set up, it is time to install Rails.

To start, open terminal and type in:

gem install rails

This process may take a while, be patient with it. Once it finishes you will have Ruby on Rails installed on your droplet.

Step Five — Deploying Rails application on web

If you want to run Rails application on Apache web server, I’d recommand using gem Phussion Passenger as so called “middleware”.

gem install passenger
passenger-install-apache2-module

…and follow instructions during processing (install required dependencies using sudo apt-get <dependencies> and update httpd.conf directives for apache web server to load passenger modules)

Make a symbolic link from your rails application’s ‘PUBLIC’ folder to web server:

ln -s /home/rails/rails_app/public /var/www/subdomains/rails_app

Create virtual host in your Apache with at least the following settings

DocumentRoot /var/www/subdomains/rails_app
RailsEnv development
<Directory "/var/www/subdomains/rails_app">
  Options Indexes FollowSymLinks -MultiViews +ExecCGI
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>

Leave a Reply