How to install PostgreSQL 9.6 on any Ubuntu version

Ubuntu Zesty (17.04)

Version 9.6 comes with the distribution.

sudo apt-get install postgresql-9.6

Ubuntu Yakkety (16.10)

sudo add-apt-repository “deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main”
wget –quiet -O – https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add –
sudo apt-get update
sudo apt-get install postgresql-9.6

Ubuntu Xenial (16.04)

sudo add-apt-repository “deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main”
wget –quiet -O – https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add –
sudo apt-get update
sudo apt-get install postgresql-9.6

Ubuntu Trusty (14.04)

sudo add-apt-repository “deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main”
wget –quiet -O – https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add –
sudo apt-get update
sudo apt-get install postgresql-9.6

Ubuntu Precise (12.04)

sudo add-apt-repository “deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main”
wget –quiet -O – https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add –
sudo apt-get update
sudo apt-get install postgresql-9.6