Version 2 (modified by chrismarx, 4 years ago) (diff)


How to install PostGIS 2.4 on Debian 9.x (stretch) from source

WIP! Work in Progress!


Several components are needed, which can either be built from source or installed from pre-built packages, as shown below. For a quick start, there are official Docker images for Postgres here

Without the Docker image, start by first installing the Postgres package:

sudo apt-get install postgresql-9.1 postgresql-server-dev-9.1 

Then for either approach, install the prerequisite packages using:

sudo apt-get install build-essential libxml2-dev libgdal-dev libproj-dev libjson0-dev xsltproc docbook-xsl docbook-mathml

Build GEOS 3.4.x

PostGIS 2.4 is best used with GEOS >= 3.7 for several new features, however Debian wheezy only has GEOS 3.5.1 available in packages, so if you want the version that enables all features, GEOS needs to be built from source. If you don't need the new features(e.g ST_FrechetDistance), you can instead install the available version of GEOS sudo apt-get libgeos-dev.

There are multiple ways to build GEOS from source, but this is the simplest (Note: currently version 3.7 is only available in the nightly build. When 3.7 is released, switch to that):

tar xfj geos-3.4.2.tar.bz2
cd geos-3.4.2
sudo make install
cd ..

Build PostGIS

tar xfz postgis-2.4.0dev.tar.gz
cd postgis-2.4.0dev

A basic configuration for PostGIS 2.4, with raster and topology support:

sudo make install
sudo ldconfig
sudo make comments-install

Spatially enabling a database

Connect to your database using pgAdminIII or psql, and use the commands to add the PostgreSQL extensions. To add PostGIS with raster support:


To add topology support, a second extension can be created on the database:

CREATE EXTENSION postgis_topology;