Setting up Ruby on Rails and PostgreSQL on Ubuntu 14.04

Posted on February 9th, 2015

In this tutorial, we will be installing Ruby via RVM, Rails, and PostgreSQL on your system running Ubuntu 14.04. I'll take you through it in what I hope are easy steps follow.

Installing Ruby
Before we install ruby it is best to get the necessary dependencies installed first

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
Now we are ready to install Ruby. By using rvm, it will be extremely easy to switch between multiple versions of Ruby if you have more than one environment set up.

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
curl -L | bash -s stable
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.1.5
rvm use 2.1.5 --default
ruby -v

The last command should print out your current version of Ruby, which should be 2.1.5 at this point. Finally, let's not install the documentation for every package you choose to install.
echo "gem: --no-ri --no-rdoc" > ~/.gemrc

Installing Rails
Before installing Rails, let's first install some necessary dependencies like NodeJS.

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

After that installation finishes, go ahead and install Rails, and check to make sure it installed correctly.

gem install rails
rails -v

Installing PostgreSQL
To install PostgreSQL, we first add a new repository, and then we are able to proceed with the install.

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.3 libpq-dev

Now with PostgreSQL installed, let's just setup a new user, and you should be good to go!

sudo -u postgres createuser yourusername -s
postgres=# \password yourusername

pgAdmin3 (Optional - Recommended)
To manage your databases a bit easier, I would recommend installing pgAdmin3, the GUI for managing PostgreSQL databases. You can do this with the following command:

sudo apt-get install pgadmin3

comments powered by Disqus
Andrew Backes

A Software Engineer living in Milwaukee, WI. Passionate about web/software development, tech, open source, and gaming.