Install Ruby On Rails on
Ubuntu 15.04 Vivid Vervet

A guide to setting up a Ruby on Rails development environment

This will take about 30 minutes.

We will be setting up a Ruby on Rails development environment on Ubuntu 15.04 Vivid Vervet.

The reason we're going to be using Ubuntu is because the majority of code you write will run on a Linux server. Ubuntu is one of the easiest Linux distributions to use with lots of documentation so it's a great one to start with.

You'll want to download the latest Desktop version here:

Some of you may choose to develop on Ubuntu Server so that your development environment matches your production server. You can find it on the same download link above.

Choose the version of Ruby you want to install:

The first step is to install some dependencies for Ruby and Rails.

To make sure we have everything necessary for Webpacker support in Rails, we're first going to start by adding the Node.js and Yarn repositories to our system before installing them.

curl -sL | sudo -E bash -
curl -sS | sudo apt-key add -
echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn

Next we're going to be installing Ruby using one of three methods. Each have their own benefits, most people prefer using rbenv these days, but if you're familiar with rvm you can follow those steps as well. I've included instructions for installing from source as well, but in general, you'll want to choose either rbenv or rvm.

Choose one method. Some of these conflict with each other, so choose the one that sounds the most interesting to you, or go with my suggestion, rbenv.

Installing with rbenv is a simple two step process. First you install rbenv, and then ruby-build:

git clone ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

rbenv install 2.5.3
rbenv global 2.5.3
ruby -v

The installation for rvm is pretty simple:

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp:// --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.5.3
rvm use 2.5.3 --default
ruby -v

Arguably the least useful Ruby setup for development is installing from source, but I thought I'd give you the steps anyways:

tar -xzvf ruby-2.5.3.tar.gz
cd ruby-2.5.3/
sudo make install
ruby -v

The last step is to install Bundler

gem install bundler

rbenv users need to run rbenv rehash after installing bundler.

We'll be using Git for our version control system so we're going to set it up to match our Github account. If you don't already have a Github account, make sure to register. It will come in handy for the future.

Replace my name and email address in the following steps with the ones you used for your Github account.

git config --global color.ui true
git config --global "YOUR NAME"
git config --global "[email protected]"
ssh-keygen -t rsa -b 4096 -C "[email protected]"

The next step is to take the newly generated SSH key and add it to your Github account. You want to copy and paste the output of the following command and paste it here.

cat ~/.ssh/

Once you've done this, you can check and see if it worked:

ssh -T [email protected]

You should get a message like this:

Hi excid3! You've successfully authenticated, but GitHub does not provide shell access.

Choose the version of Rails you want to install:

Since Rails ships with so many dependencies these days, we're going to need to install a Javascript runtime like NodeJS. This lets you use Coffeescript and the Asset Pipeline in Rails which combines and minifies your javascript to provide a faster production environment.

To install NodeJS, we're going to add it using the official repository:

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

And now, without further adieu:

gem install rails -v 5.2.1

If you're using rbenv, you'll need to run the following command to make the rails executable available:

rbenv rehash

Now that you've installed Rails, you can run the rails -v command to make sure you have everything installed correctly:

rails -v
# Rails 5.2.1

If you get a different result for some reason, it means your environment may not be setup properly.

Rails ships with sqlite3 as the default database. Chances are you won't want to use it because it's stored as a simple file on disk. You'll probably want something more robust like MySQL or PostgreSQL.

There is a lot of documentation on both, so you can just pick one that seems like you'll be more comfortable with. If you're coming from PHP, you may already be familiar with MySQL. If you're new to databases, I'd suggest skipping to setting up PostgreSQL.

You can install MySQL server and client from the packages in the Ubuntu repository. As part of the installation process, you'll set the password for the root user. This information will go into your Rails app's database.yml file in the future.

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Installing the libmysqlclient-dev gives you the necessary files to compile the mysql2 gem which is what Rails will use to connect to MySQL when you setup your Rails app.

When you're finished, you can skip to the Final Steps.

For PostgreSQL, we're going to add a new repository to easily install a recent version of Postgres.

sudo sh -c "echo 'deb precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.5 libpq-dev

The postgres installation doesn't setup a user for you, so you'll need to follow these steps to create a user with permission to create databases. Feel free to replace chris with your username.

sudo -u postgres createuser chris -s

# If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password chris

And now for the moment of truth. Let's create your first Rails application:

#### If you want to use SQLite (not recommended)
rails new myapp

#### If you want to use MySQL
rails new myapp -d mysql

#### If you want to use Postgres
# Note that this will expect a postgres user with the same username
# as your app, you may need to edit config/database.yml to match the
# user you created earlier
rails new myapp -d postgresql

# Move into the application directory
cd myapp

# If you setup MySQL or Postgres with a username/password, modify the
# config/database.yml file to contain the username/password that you specified

# Create the database
rake db:create

rails server

You can now visit http://localhost:3000 to view your new website!

Now that you've got your machine setup, it's time to start building some Rails applications.

If you received an error that said Access denied for user 'root'@'localhost' (using password: NO) then you need to update your config/database.yml file to match the database username and password.



Worked like a charm testing out on 15.04 with the exception I had to change the repository back to utopic for nodejs and had to add the gpg key for rvm.. great article.. thanks


Awesome! I'll be sure to tweak those soon since the final release comes out soon!


Cloning into '.rbenv'...
fatal: unable to connect to Temporary failure in name resolution


the proxy might be the problem,


Minor inconsistency at the top of the post you recommend 14.10 Trusty Tahr. The 14.10 release is actually Utopic Unicorn, and 14.04 LTS is Trusty Tahr.


Ah! Thanks. You find my copy-paste job from last version. ;)



I tried to install using rvm but I get this error.

Error running 'requirements_debian_update_system ruby-2.2.1',

showing last 15 lines of /home/bagus/.rvm/log/1428510134_ruby-2.2.1/update_system.log

++ case "${TERM:-dumb}" in

++ case "$1" in

++ [[ -t 2 ]]

++ return 1

++ printf %b 'There has been error while updating '\''apt-get'\'', please give it some time and try again later.

404 errors should be fixed for rvm to proceed. Check your sources configured in:




There has been error while updating 'apt-get', please give it some time and try again later.

404 errors should be fixed for rvm to proceed. Check your sources configured in:



++ return 100

Requirements installation failed with status: 100.


Sounds like you've got issues with apt-get running. Other people have had the same issue it looks like so you'll want to make sure that you can run "sudo apt-get update" successfully it seems.


Thanks, perfect work!!!


It looks like the PPA hasnt' been updated for 15.04 yet. For now, replace that step with "sudo apt-get install nodejs" and you should be fine.


Some problems before and after install of Ruby 2.2.2 with rbenv on (l)ubuntu 15.04:

1. The Ruby openssl extension was not compiled. Missing the OpenSSL lib?

Solution for me was

sudo apt-get install libssl-dev

2. On an error:

Sorry, you can't use byebug without Readline. To solve this, you need to rebuild Ruby with Readline support. If using Ubuntu, try sudo apt-get install libreadline-dev and then reinstall your Ruby.

Solution for me was

sudo apt-get install libreadline-dev
CONFIGURE_OPTS="--with-readline-dir=/usr/include/readline" rbenv install 2.2.2


Thanks simple and easy :-)


Thanks a lot. Awesome guide, worked flawlessly :)


very good guide and clear steps, it works on my virtual box


I don't know but I almost every time have to " sudo /etc/init.d/postgresql restart


I have the same issue ..


The nodejs ppa:chris-lea/node.js sometimes you get the 404 error

it is better just to go with the

curl -sL | sudo bash -



sudo apt-get install -y nodejs


this works fine every time


also for postgresql when creating user some times you get the


createuser: could not connect to database postgres: could not connect to server: No such file or directory

Is the server running locally and accepting

connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
restart with
sudo /etc/init.d/postgresql restart

and your good to go


Many thanks for this great post!


What is the advantage of the nodejs you get from the PPA? Ubuntu seems to have nodejs in their repo by default also.


The difference is just that the PPA gets updated more often (if the maintainer keeps up to date) vs the Ubuntu repo which only gets updated once every major version change. You'll get a stable version of Nodejs, but it will only receive small updates and security fixes, not major version changes.


many thanks, but i have a problem installing rails with this command: gem install rails -v 4.2.1
this is the result:

ERROR: While executing gem ... (Gem::RemoteFetcher::UnknownHostError)
no such name (

please help me to find the solution, thanks again


You may need 'rbenv rehash' after setting ruby global version.


Under your "Using rvm" instructions, they require that you be using a 'bash' shell (the commands would not work with a 'tcsh' shell). Also, the curl command errored the first time, requiring the downloading of a gpg key from and then doing it again. Finally, (if you're installing as root, anyway) the path was /usr/local/rvm/scripts/rvm ..not ~/.rvm/scripts/rvm (I typically run as root while doing the initial setups of various services and software on a new machine.)


Actually, I couldn't get much of anything to work with the rvm setup. So, I went the easy route and just "apt-get install ruby ruby-dev". It's an older version, but I think it has everything I need.


rvm has first tier support for bash, and nominal support for zsh, and WILL NOT WORK in other shells. rbenv is the tool you need to use for other shells, or just do things manually.


Just the best guidance ever, thanks guys!


I got error on Ubuntu 15.04 with mysql2:
Gem::LoadError: can't activate mysql2 (~> 0.3.13), already activated mysql2-0.4.1. Make sure all dependencies are added to Gemfile.

But this will help:


Worked as written for version 15.04. Ready for my rails intro tomorrow, thanks!


Works great, I only had a problem with the mysql2 gem. I fixed that by doing a downgrade to version 0.3.18.

gem 'mysql2', '~> 0.3.18'


had the same issue, thanks for the solution! :D


"Access denied for user 'root'@'localhost' (using password: NO)Please provide the root password for your MySQL installation" - getting this message when run "rake db:create" I have set the password in databases.yml password to my root password file but show this problem. Thanks in advance. (Note: I am newbie in CLI environment)


I just googled and found this:

Since it is part of the repositories it is no longer required to add the ppa. I am using Ubuntu 15.04


I'm getting this error on

$ rake db:create

Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

Gem::LoadError: can't activate mysql2 (~> 0.3.13), already activated mysql2-0.4.2. Make sure all dependencies are added to Gemfile.

Tasks: TOP => db:create

(See full trace by running task with --trace)


Fixed it by adding

gem 'mysql2', '~> 0.3.18'

instead of

gem 'mysql2'

in Gemfile of the app.

## Great post Thanks.


Hi thevaliantx, you have to modify the Gemfile with that version for mysql2 gem.Then run "bundle install".


That's nice! I'm trying to be a full stack web developer, so HTML and CSS is mandatory, besides much more things to learn. But I'm not following the Ruby path, I was just trying to know how it works, but instead I'm really focused in Node.js. I'm not a professional programmer too, but maybe someday.


A JavaScript book that I always recommend is: "Eloquent JavaScript - second edition". It's divided in three parts, the last one is about Node.js. I thinks i'ts a good book for new comers to the language. You can read it online for free:


No problem mate, always glad to help.

Login or create an account to join the conversation.