How to install postgresql9.4 in ubuntu server

Why Postgres?

PostgreSQL is a fantastic database platform. Postgres is open source, cross-platform, free, and offers an amazing feature set which, in my mind, exceeds those of its principle peers in the relational database space.

Postgres offers all of the (mostly) standards-compliant SQL/relational database feature you would expect, plus a host of exciting and innovative features. Highlights include a JSON datatype (and also JSONB!), an array datatype, and the new HStore type, which essentially allows the specification of a column as containing a list of key/value pairs. We’ll take a tour of PostgreSQL in another post, but first, let’s get the thing installed and running.

Fortunately, the PostgreSQL Global Development Group (PGDB) maintain an APT repository of PostgreSQL packages for Debian and Ubuntu-derived Linux distros.

Add the Postgres Package Source for Your Linux Release

We need to create a sources file reflecting the proper Postgres source for our particular distro. In my case, as noted above, we need the source compatible with the “Trusty” release of Ubuntu. So we can do this from the terminal to add the file (make sure you use sudo in all of the following steps):
Add the PGDB APT Source file From the Terminal:
Hide Copy Code

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

Now that the file exists, open in your editor of choice (we’ll use gedit here):
Open the pgdg.list File in gedit (use sudo):
Hide Copy Code

$ sudo gedit /etc/apt/sources.list.d/pgdg.list

then add the following line in gedit and save (where I used “trusty” below, use the name of your release for Ubuntu, or the corresponding Ubuntu release if you you are using Linux Mint):
Add the Postgres Package Repository and Specify Your Distro Release:
Hide Copy Code

deb trusty-pgdg main

Save, and close gedit.

Alternately, we can achieve all of the above in one shot from the terminal like so (take note of the placement of single and double quotes here…):
Add the Package Source in one multi-line Terminal Command:
Hide Copy Code

$ sudo sh -c \
‘echo “deb trusty-pgdg main” > \

Add the Postgres Package Repository Key

Next, add the package repository key:
Add the Postgres Package Repository Key:
Hide Copy Code

$ sudo apt-get install wget ca-certificates
$ wget –quiet -O – | sudo apt-key add –

Update, Upgrade, and Install Postgres

Then, we need to update our package sources:
Update Package Sources:
Hide Copy Code

$ sudo apt-get update

Once that’s done, we need to upgrade packages to the latest versions:
Upgrade Packages:
Hide Copy Code

$ sudo apt-get upgrade

Note, this can be a long process. Also, you may be prompted at several points to make some choices about configuration items. Specifically, you may informed that this that or the other configuration file has been changed, and asked if you want to keep your original version, or replace with the package maintainer’s version. Select “Y” to accept the package maintainer’s version in these cases.

When the upgrade process finishes, we are ready to install Postgres (we’ll also include pgadmin3):
Install Postgres:
Hide Copy Code

$ sudo apt-get install postgresql-9.4 pgadmin3

Leave a Reply