Today’s guide will cover how to install PostGIS on Ubuntu 20.04/18.04 | Debian 10 Linux. PostGIS is an open source PostgreSQL database extension for creating Geographic objects on the PostgreSQL object relational database. The features of PostGIS are derived from Open Geospatial Consortium SQL specifications.

postgis debian ubuntu

PostGIS can be installed on Ubuntu, Debian, SUSE Linux, Red Hat based Linux systems such as CentOS, Scientific Linux, Windows and macOS. The PostgreSQL build team has packages for Debian and Ubuntu for several versions of PostgreSQL. We’ll add the PostGIS APT repository for PostgreSQL and install PostGIS on Ubuntu 20.04/18.04 / Debian 10 from it.

Let’s now kickstart the installation of PostGIS on Ubuntu 20.04/18.04 / Debian 10 Linux system.

Step 1: Update system

You can do APT package list update and system upgrade before you get started.

sudo apt update
sudo apt -y upgrade

A reboot is necessary after an upgrade.

sudo reboot

Step 2: Add PostgreSQL repository

Before you start the installation of PostGIS on Ubuntu 20.04/18.04 / Debian 10 Linux, you’ve to add PostgreSQL APT repository to your system where binary packages will be downloaded and installed.

sudo apt -y install gnupg2
wget --quiet -O - | sudo apt-key add -

After importing GPG key, add PostgreSQL APT repository.

echo "deb `lsb_release -cs`-pgdg main" |sudo tee  /etc/apt/sources.list.d/pgdg.list

Step 3: Install PostgreSQL Database Server

PostgreSQL is required to be installed before installation of PostGIS on Debian / Ubuntu. Use our previous guides for this installation.

PostgreSQL 11:

Install PostgreSQL 11 on Ubuntu

Install PostgreSQL 11 on Debian 10

PostgreSQL 12:

Install PostgreSQL 12 on Ubuntu

Install PostgreSQL 12 on Debian 10

For different version of PostgreSQL, replace version number with your desired installation version.

Step 4: Install PostGIS on Ubuntu 20.04/18.04 / Debian 10

After the installation of PostgreSQL, proceed to install PostGIS on Ubuntu 20.04/18.04 / Debian 10 Linux distribution.

With PostgreSQL 12:

sudo apt install postgis postgresql-12-postgis-3

The next is for PostgreSQL 11. Replace 11 with your PostgreSQL version.

sudo apt update
sudo apt install postgis postgresql-11-postgis-3

Step 5: Enable PostGIS on Debian 10 / Ubuntu 20.04/18.04

You need to activate PostGIS features on a database before you can store spacial data. The example below will show you how to create a database and activate the Spacial features.

1.Switch to postgres user.

sudo -i -u postgres

2.Create test user/database.

-bash-4.2$ createuser postgis_test
-bash-4.2$ createdb postgis_db -O postgis_test

3.Connect to the test database:

-bash-4.2$ psql -d postgis_db
psql (11.5 (Debian 11.5-3.pgdg100+1))
Type "help" for help.

4.Enable the PostGIS extension on the database:

postgis_db=# CREATE EXTENSION postgis;

5. Verify PostGIS is working

postgis_db=# SELECT PostGIS_version();
(1 row)

For more PostGIS mastery, visit the PostGIS Documentation website.

Similar guides:

Install PostGIS on CentOS 7

How To Install pgAdmin 4 on Ubuntu

How to Install pgAdmin 4 on Debian

How to Install pgAdmin 4 on CentOS 7 & Fedora

How to Install pgAdmin4 on FreeBSD 12

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here