Setup Ruby On Rails on
Ubuntu 14.10 Utopic Unicorn

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 14.10 Utopic Unicorn.

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 python-software-properties 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.0
rbenv global 2.5.0
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.0
rvm use 2.5.0 --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.0.tar.gz
cd ruby-2.5.0/
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.1.4

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.1.4

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.



Giorgio Martini on


Jeb Baxley on

Hi, looks like it didn't want to create the database for me with the rake command. I had to log into postgresql and add it manually.

just thought you should know.

Martin Dimmock on

Yeah I got this too. I just closed then restarted the terminal and tried again - worked!

I'm a complete nube to the *nix environment, Ruby, etc., having used only Windows since 1990.

Jeb Baxley on

Thanks, yeah I didn't try that. Let me know if you run into any problems, I've been using *nix for awhile and am a Win sys admin by trade.

Martin Dimmock on

Thanks Jeb, will do.

TechYari on

Thanks for the steps. Worked like a charm :)

Andreas S on

Wonderful guide, worked great for me. I was trying to set up a virtual instance on Amazon, first using their Amazon Linux AMI. Scapped two instances after the ruby on rails (dependencies, user rights, missing files, etc bla bla etc) was pretty broken and messy. Started a new virtual instance running Ubuntu instead and followed your steps. Much better. It's quite a lengthy process but in the end everything worked like a charm, thanks to you!

shashank shandilya (10 XP) on

its saying rvm not found what to do

Altamiro Junior on

Execute: gpg --keyserver hkp:// --recv-keys D39DC0E3

After: source ~/.rvm/scripts/rvm

Jason on

Great tutorial. Thank you very much.

As a side note, PostgreSQL offers repositories for recent Ubuntu versions. In the tutorial, you are using the Ubuntu Precise repository no matter which Ubuntu version one selects at the beginning oof tutorial. After some research I found out that PostregreSQL offers differents repositories depending on the Ubuntu version. That would be nice to add to the tutorial as well, just in case.

Chris Oliver (162,220 XP) on

Thanks Jason! I think at the time they didn't have anything past precise. I'm glad they got Trusty and Utopic in there!

Jason on

It's no big deal. I just tought it was worth mentioning. I'm learning RoR and this has been one of the best tutorials on how to setup your environment! Very easy. Thanks.

Rael Gugelmin Cunha on

Other alternative is to use the RVM PPA (so, automatic updates):

Isaac Andrade on

Great article! Helped me a ton!

Just an update, the command below is deprecated:

echo "gem: --no-ri --no-rdoc" > ~/.gemrc

now it should be:

echo "gem: --no-document" > ~/.gemrc

Chris Oliver (162,220 XP) on

Awesome, thanks for the heads up Isaac!

Leo on

All the process went fine but for some reason I cant see the page on localhost:3000.
It´s giving me a "page not available" error.

Last terminal output is:

[email protected]:~/myapp$ rails server
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-02-14 23:50:43] INFO WEBrick 1.3.1
[2015-02-14 23:50:43] INFO ruby 2.1.5 (2014-11-13) [x86_64-linux]
[2015-02-14 23:50:43] INFO WEBrick::HTTPServer#start: pid=18421 port=3000

Wez Baker on

I had the same problem, but only when trying to connect from another machine on my network. Tried from local and it works successfully. How to open up the server other hosts?

Leo on

I found out I´m having the problem because my app is only accepting requests from local adapter. The work around I´m using now is to initialize the server with:
rails s - b

This will make webrick accept requests from any interface.
Check if this works for you.

Anyway, I´m still trying to discover how to make this the default behaviour for "rails server" command.

Leo on

Also if your using any kind of virtual machine, make sure your local and VM ports are mapped.

Pao Yang on

up and running with Rails in less than 2 hours with your tutorial

1000 thank-yous....

Byan on

thank you very much for saving my time :D

kareem gan (10 XP) on

Question, for exporting the rbenv, what's the best way to handle both OSX and Ubuntu? Because I use dotfiles for my zsh and want to just have one file for my zshenv.

Chris Oliver (162,220 XP) on

I personally store my configs in a Git repo, clone it on each machine, and symlink the configs.

Hamed Qaderi on

Thanks very much! It didn't took even 20 minutes.

Ricardo Chirino on

Question here.
Working on a Linux VM using VirtualBox.
I'm configuring Git and I added the key to my settings.

When I run:

ssh -T [email protected]

I get the following message:
[email protected]:~$ ssh -T [email protected]
Warning: Permanently added the RSA host key for IP address '' to the list of known hosts.
Permission denied (publickey).

Any ideas on how to correct this? Also, can I continue the installation steps and fix this later?


Ricardo Chirino on

SOLVED didn't copy my keys in the proper location

Paul Bartsch (10 XP) on

Thanks Chris! These are probably the clearest installation instructions I've read.

Chris Oliver (162,220 XP) on

You're welcome! I'm glad I was able to help. :)

Kevin Townsend (310 XP) on

I agree. Totally new and the install process was very confusing when using Thanks for the clear instructions.

Nikola Okonesh (210 XP) on

Вы забыли упомянуть "Terminal" -> Profile -> Parameters profile -> Heading and command -> Tick this To start a command as an envelope of an input.

Shravan kumar on


Jamrodh Singh on

i have a problem....please help me

WiseOne111 on

When I type:

echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL I get an error message: line 124 unepected EOF while looking for matching '"' and line 125 syntax error unexpected end of file.

Savvanis Spyros on

thx a lot my friend., work like charm without errors on ubuntu mate 14.10. cheers

Pierre-Yves Mathieu on

Hi Chris,

Thank you very much for GoRails, I have been using it to setup all my
project. Lately, I switched to Docker and tought Your community would
probably be interested in a faster and more consistent way to set up a
development environement. Please let me know what you think of this
simple docker box I created.

Install Docker and docker-compose, try google!

1 - run: .
2 - wait..., say yes, wait...
then start the dev server:
3 - docker-compose up

look your new server is running on localhost:3000

there's even a box for developping rails gem

I would be very happy to hear from you, If you have any concerns, please tell me!

Chris Oliver (162,220 XP) on

This is awesome and I'm definitely going to check it out tomorrow!

Pierre-Yves Mathieu on

Have you been able to use it? I would love your feedback to make it easier and better.

José D. Romero Vega on

Thanks is a great TUTORIAL! but i have a problem


I do this:
~$ rails new myapp -d mysql

and after I get this in the last part (after create all the stuff)

Fetching gem metadata from
Fetching version metadata from
Fetching dependency metadata from
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0

Bundler::GemspecError: Could not read gem at /home/jodarove/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/cache/json-1.8.2.gem. It may be corrupted.
An error occurred while installing json (1.8.2), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.2'` succeeds before bundling.
run bundle exec spring binstub --all
bundler: command not found: spring
Install missing gem executables with `bundle install`

so I read in another blog the solution ( https://taimoorchangaizpuci... )

I need do this to clear the cache
~$ rm -rf /home/jodarove/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/cache/
where says jodarove change for your user name
and after that I execute again: rails new myapp -d mysql

brainlara on

Great information, on installing ROR in ubuntu.

Ruby on Rails Development in India

saravanan on

i have followed all steps. whenever i run "rake db:create".
It will returns following error:

Couldn't create database for {"adapter"=>"postgresql", "pool"=>5, "username"=>"postgres", "password"=>nil, "database"=>"homeporte_development"}
WARNING: password file "/home/saravanan/.pgpass" has group or world access; permissions should be u=rw (0600) or less
FATAL: Peer authentication failed for user "postgres"

Junaid Farooq on

rbenv install 2.2.2
This part took my whole life and am still waiting for its completion buddy

Leonardo Godoy on

Hi! Thanks for the instructions. But, i have a problem. I'm installing on Ubuntu 14.04 clear system, but, when I put the rbenv install 2.2.3 command, in terminal shows "Installing ruby-2.2.3..." and stays here more of 2 hours. Why is too slow the installation? It's good or something else is bad in the installation? I will appreciate the help

Chris Oliver (162,220 XP) on

That seems awfully long. Usually it's about 15 minutes or so. Sometimes it can stall because of low ram. You might restart it and see if it finishes sooner. I'd also recommend trying the $10/mo server because it has a bit more power for compiling.

Leonardo Godoy on

Something I mistake: I have installed Ubuntu on VMWare Virtual Machine. I had add more memory, on limit of 32bit O.S., but, i had the same problem. After that, i should install from source, and now it's working. I hope that will works finally.
Edit: Finally, works. But, only i need install from source. rbenv doesn't work.
Second edit: When you go to install rails 4.2.4, the command should be "sudo gem install rails -v 4.2.4", if not insert "sudo" access, will show an error with the install.

maciek on

thx for Tut. Works great on deepin with rvm method!

ZaS1ification on

Thank you very much! It's much simple and powerfull article!

BloodyMery (10 XP) on

Thank you! I think every new project I start begins with visit this page.

Chris Oliver (162,220 XP) on

Whoo! Thank you thank you! :)

Sajjad Murtaza (10 XP) on

Nice tutorial (y)

Rodrigo F. Azevedo on

Thanks dude. This tutorial saved my day!

Pierre Gagnon on

Hi, When i run

ssh -T [email protected],

I have the following message:

/etc/ssh/ssh_config: line 54: Bad configuration option: subsystem

Unsupported Match attribute group

/etc/ssh/ssh_config line 55: Bad Match condition

I try to gererate another Key and i receive the same message ?

I edit the ssh_config file and on line 54 and 55, i have :

Match group ftpaccess
ChrootDirectory %h

So what is the problem ?

pawan bhat (10 XP) on

Hi All,
i have install ruby from source
after instillation when i run "gem install bundler" it gives below error

ERROR: Loading command: install (LoadError)

cannot load such file -- zlib

ERROR: While executing gem ... (NoMethodError)

undefined method `invoke_with_build_args' for nil:NilClass

i check zlib but it is already installed
Please help to resolve this issue

lucas on

o meu nao deu certo

Login or create an account to join the conversation.