We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Install Ruby On Rails on Ubuntu 12.04 LTS with rbenv

PostedApril 12, 2013 69.1k views Ruby on Rails Ruby Ubuntu


Ruby On Rails (in short, Rails) is one of the most popular web development framework, In fact currently it's the hottest web development stack, especially for Saas (Software as a Service) apps.


Before installing Rails, I assume that you have already setup the server (created users, setup ssh etc). You can find how to do this here: Ubuntu Server Setup.

Step One - Install rbenv and dependencies

Before, installing any package, it's always recommended to update package repository cache.

sudo apt-get update

Now, install git, curl and nodejs (javascript runtime is required in newer version of Rails). nodejs package is pretty outdated in official package repository, so install it from the PPA.

sudo apt-add-repository -y ppa:chris-lea/node.js

If you get the response sudo: apt-add-repository: command not found, you need to take one more step and install python properties to help you manage the repositories:

sudo apt-get install python-software-properties

Subsequently, you can take the next steps:

sudo apt-get -y update
sudo apt-get -y install curl git-core nodejs

Installing rbenv using a Installer

rbenv is a simple tool for managing multiple ruby versions, it's like RVM (so you could also use RVM) but it's light-weight and more simpler. To install rbenv we are using a simple script (hosted on github, you can checkout the code if you have any doubt).

First run the script,

curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash

Now, update bashrc according to the instruction, add these lines to the top of your bashrc file:

nano ~/.bashrc
export RBENV_ROOT="${HOME}/.rbenv"
if [ -d "${RBENV_ROOT}" ]; then
  export PATH="${RBENV_ROOT}/bin:${PATH}"
  eval "$(rbenv init -)"

Next, reload the shell.

source ~/.bashrc

Then, you should install the dependencies (using the installer tool),

rbenv bootstrap-ubuntu-12-04

Step Two - Install Ruby & gems

Install Ruby (and make it the default, that's what the global option does here) and gems -

rbenv install 1.9.3-p392
rbenv rehash
rbenv global 1.9.3-p392

For Bundler and rake

gem install rdoc
gem install bundler
gem install rake 
rbenv rehash

Step Three - Install Rails

Now, you can install the rails gem in one simple command -

gem install rails


Creative Commons License