How to install PostGIS 2.3 on Ubuntu 16.04 LTS

Hey guys,
today about the installation of PostGIS, an open source and OGC compliant spatial database extender for the PostgreSQL database management system. It is similar in functionality to ESRI ArcSDE, Oracle Spatial, DB2 spatial extender and something (SQL Server spatial…?)from Microsoft. It provides outstanding performance and functionality – for free! At this time the latest stable release is PostGIS Version 2.3.2. This Blogpost should give you an idea of how to install PostGIS in a stable and secure environment: The commonly used Debian-based Linux operating system Ubuntu 16.04 LTS.

For all following commands use your terminal.

At firtst you need a working PostgreSQL DBMS. By default Ubuntu 16.04 (Xenial) comes with PostgreSQL 9.5 in its repositories.
As you want to install current version 9.6 you have to add the official PostgreSQL Apt Repository to your sources.list:

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

Import the relevant signing key:

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

Update your packages:

sudo apt update

Start installing PostgreSQL 9.6 and the “contrib” package to add additional utilities and functionality to the database:

sudo apt install postgresql-9.6 postgresql-contrib-9.6

Check your PostgreSQL Version:

psql --version

The output should look somehow like this:

psql (PostgreSQL) 9.6.2

Create a new database user(replace “simon” with your name):

sudo -u postgres createuser -P simon

You will be prompted for a password. As always: Use a strong password here!

Create a new database (replace “simon” with your username and “gisdata” with whatever you want to name your database):

sudo -u postgres createdb -O simon gisdata

Test if your database works correctly:

psql -h localhost -U simon gisdata

As an output you should see something like this:

 psql (9.6.2)
 SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
 Type "help" for help.

gisdata=>

Exit psql:

 \q

Now, let’s add PostGIS support to your database:

Add UbuntuGIS-unstable repository and update packages:

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt update

Install PostGIS:

sudo apt install postgis postgresql-9.6-postgis-2.3

Create extensions for your postgres database:

sudo -u postgres psql -c "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;" gisdata

That’s it! Part 2 will follow – It will be about how to config PostGIS for remote access and how to work with a geospatial database in combination with QGIS.

About This Author

Simon is a research assistant in the field of remote sensing at Technical University of Munich (TUM). Currently he is working on methods to describe reed ecosystem parameters with the help of hyperpectral and LiDAR data. Besides geoinformatics he loves to do outdoor activities such as hiking and climbing.

15 Comments

You can post comments in this post.


  • Very well structured and up to the point tutorial! Thanks! Definitely helpful for future postgis installations.

    Martin 6 years ago Reply


  • Very nice tutorial for the latest postgresql and postgis ! Thank you very much sir !

    Ben 6 years ago Reply


  • Nice!
    Always I’ve appreciate straightforward tutorials like this.
    Thank you very much!

    Milo 6 years ago Reply


  • Great tutorial, simple and easy. Thank you very much 🙂

    Filip Zorić 6 years ago Reply


  • This was just what I was looking for– thank you!

    Charlie 6 years ago Reply


  • Very helpful! But the last step wasn’t successful for me, it says: FEHLER: konnte Erweiterungskontrolldatei »/usr/share/postgresql/9.3/extension/postgis.control« nicht öffnen: Datei oder Verzeichnis nicht gefunden. What do you think could it mean? Will be very thankful for a hint!

    Ardak 6 years ago Reply


    • Looks like your psotgis-isntallation was not successful. Try the previous step again: sudo apt install postgis postgresql-9.6-postgis-2.3
      A basic tip: google your errors 😉

      Simon 6 years ago Reply


  • I cannot find the part 2. Have you already posted it online or have you yet to do that?

    Vaskar Dahal 6 years ago Reply


  • Thanks Simon! New in this. Hope ‘ll get great help from you in future!

    Saikat Maiti 5 years ago Reply


  • Could you help me please! I need to install postgres in a VM with Linux Ubuntu 14.04. But occurs an error in command sudo apt install postgresql-9.6 postgresql-contrib-9.6:

    The following packages have unmet dependencies:
    postgresql-9.6 : Depends: postgresql-common (>= 171~) but it is not going to be installed
    Depends: libsystemd0 but it is not installable
    Recommends: postgresql-contrib-9.6 but it is not going to be installed
    Recommends: sysstat but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.

    I don’t know what is happen. Please, help me if you can. Many thanks

    Felipe Carvalho 5 years ago Reply


Post A Reply

*