87

How do I install PostgreSQL 9.6 on any Ubuntu version since it doesn't come by default with the most recent version?

Ubuntu Xenial (16.04) comes with PostgreSQL 9.5 from the default repositories.

196

For the following Ubuntu versions, you can install with the given commands, as per the official PostgreSQL Apt Repository.

Ubuntu 17.04 - 17.10

Version 9.6 comes with the distribution.

sudo apt-get install postgresql-9.6

Ubuntu 14.04, 16.04

sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-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
  • 6
    I removed 15.10: it is no longer supported so we should not advice it ;-) – Rinzwind Oct 2 '16 at 7:29
  • Install needed commands before: apt-get install wget software-properties-common – orgoj Oct 11 '17 at 7:38
  • After install, check service postgresql status, and restart if necessary. – Peter Krauss Dec 23 '17 at 21:19
  • 1
    apt (instead apt-get) is recommended in nowadays. – Peter Krauss Dec 23 '17 at 21:20
  • See answer from @Anvesh, you must use https – riley Jun 21 '18 at 21:14
14

Follow below steps:

Reference is taken from this blog.

You need to add the latest PostgreSQL repository for the latest version.

sudo add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main"

Update and Install PostgreSQL 9.6:

sudo apt-get update
sudo apt-get install postgresql-9.6

Default postgres super user and postgres database is created. You need to set a password for the postgres super user.

ubuntu@:~$ sudo passwd postgres
Enter new UNIX password:****
Retype new UNIX password:****
passwd: password updated successfully

If service is not started, you can start the PostgreSQL service.

sudo service postgresql start

Connect PostgreSQL server using postgres user:

ubuntu@:~$ su postgres
Password:****

Create a sample database:

createdb database_name

Connect to that database:

psql -d database_name
  • What is the password for the postgres user? you just wrote **** – light24bulbs Jun 1 '17 at 22:29
  • 1
    @light24bulbs The password is the same as we set with sudo passwd postgres – Niklas Rosencrantz Jul 14 '17 at 6:57
2

I followed this Github gist - I am running ubuntu xenial inside vagrant and wanted to upgrade existing postresql official repository vesion 9.5 to 9.6 so that I can use PostGIS extension which is served best by version 9.6 (officially mentioned in their site) Hope this helps someone.

  • 3
    Please add the steps in case that link goes dead – George Udosen Jun 24 '17 at 14:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.