Install PostreSQL 9.2 on Ubuntu 13.04

Intro

It's super easy to install default version of PosgtreSQL on Ubuntu. Usually it is just: apt-get install postgresql.

However if you need to install version that became available after Ubuntu release than it is a little bit more complicated. E.x. PostgreSQL 9.2 was released after Ubuntu 13.04 version. Read about this in official documentation. Also check this StackOverflow discussion.

Instructions

Install missing dependencies:

sudo apt-get install libpq-dev libpq5.

Add PostgreSQL repo:

sudo su; echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' >> /etc/apt/sources.list.d/pgdg.list

Add the key:

wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -

Update repositories:

sudo apt-get update

Install PostgreSQL:

sudo apt-get -t raring install postgresql-common -t raring postgresql-9.2 postgresql-client-9.2

In this example I'm installing just PostgreSQL server and client, but you can also install 'postgresql-contrib-9.2' package in addition.

Conclusion

I tried this on DigitalOcean Ubuntu instance and it worked great. Actually this instructions are heavily inspired by following post. I found other instructions that tried to solve same problem but they didn't work for me.