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.
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
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 -)" fi
Next, reload the shell.
source ~/.bashrc
Then, you should install the dependencies (using the installer tool),
rbenv bootstrap-ubuntu-12-04
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
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.
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!
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
@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.
@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.