// Tutorial //

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

Published on April 12, 2013
Default avatar

By Ramesh Jha

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

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.


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

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us

About the authors
Default avatar
Ramesh Jha


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
May 20, 2014

@guoqiang_huang1 and @adam.miribyan: Thanks for the heads up! I’ll update the article.

Hi, frustrated when the steps wasn’t working. and foudn that the rbenv-installer address had changed, see adam.miribyan’s comments as well.

It looks like the rbenv-installer script url has been changed to https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer.

Neil, A perfect way to save commands. I use zsh, and in my .zshrc I save terminal entries to a .history file. It is perfect for keeping that of these types of things. I am pretty sure bash can do the same thing.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
June 10, 2013

@nick4jesus it might be running out of memory. Try adding swap to your droplet: https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04

When I try to install a ruby, the compile process keeps getting killed, why?

This all worked perfectly. Got rbenv up and running. Now for Passenger, Nginx and Rails. Is there a way I can sort of save it all so far so I can revert to it if required?

@ dougquesnel: Exactly right. In 12.10 server apt-add-repository is in software-properties-common (not python-software-properties) The correct line for 12.10 is:

sudo apt-get install software-properties-common

I had to install software-properties-common to get it to show up.

Even after installing python-software properties it still says command not found.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel