PostgreSQL or referred to as its original, abbreviated name Postgres, is an object-relational database management system (ORDBMS) with an emphasis on storing data securely and through best practices.For this tutorial, I’m using Ubuntu 14.04 x64 with 512 MB of RAM from Digital Ocean. The cost is only $5 per month!

Install PostgreSQL

Installing PostgreSQL through apt-get is quick and easy; just two (2) commands.

We will first do a package repository update:

sudo apt-get update  

Next, we will install PostgreSQL:

sudo apt-get install postgresql

Let’s check to mak sure PostgreSQL is installed and what version has been installed:

psql -V

Make sure the -V is capitalized in the above command.

Install PostgreSQL through a PPA

If that doesn’t work or if you want other versions of PostgreSQL than the standard one, you can install PostgreSQL through a PPA repository:

sudo apt-get update  
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update  
sudo apt-get install postgresql

PostgreSQL Apt Repository

Instead of a PPA repository, it’s recommended to use PostgreSQL Apt Repository because the PPA repository is deprecated, the PostgreSQL Apt Repository has a lot more packages, will receive updates and has better QA.

First create the file /etc/apt/sources.list.d/pgdg.list:

touch /etc/apt/sources.list.d/pgdg.list

Open the file:

vi /etc/apt/sources.list.d/pgdg.list

And add the following line to it (shift + i):

deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main

Save and exit (:wq!).

Now import the repository signing key, and update the package lists:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update

Now we can install a PostgreSQL version of your choice. In this example, I’m going to use the latest version of PostgreSQL:

apt-get install postgresql-9.4

Let’s check to make sure PostgreSQl and the version we wanted has been installed. You should see something like this:

psql (PostgreSQL) 9.4.0

You’re done!