Compiling from Source

PostGIS has many packaged installations, but if you are more adventurous and want to compile your own, refer to our source download and compilation instructions:

Binary Installers

Binary distributions of PostGIS are available for various operating systems.

Docker

PostGIS has a community docker-postgis project. Production ready PostGIS Docker builds can be pulled from PostGIS docker hub

Windows

  • More details about getting up and running with windows can be found on Windows Downloads page.

Red Hat / Centos / Scientific Linux

Ubuntu / Debian

OSX

  • A popular distribution particularly for newbies is Postgres.app. It includes generally latest version of PostgreSQL, PostGIS, and PLV8. Great for development and testing. Do not mix with other installations.

  • Homebrew users can just run "brew install postgis" and tends to be a favorite for more advanced users since there are brew scripts for most of the popular PostgreSQL extensions, not always present in other Mac distributions.

  • The EnterpriseDb OSX PostgreSQL combination from EnterpriseDB includes generally latest stable minor version of PostGIS.

  • The builds from KyngChaos are a little dated but useful for older PostGIS versions. Read the instructions carefully. Do not mix with other installations.

OpenSUSE and SUSE

Distributions targeting more than one OS (these include PostgreSQL and many other PostgreSQL extensions)

  • EnterpriseDb PostgreSQL - Supports 32-bit/64-bit Linux, MacOSX, Windows Note that the MacOSX PostGIS package and EDB Windows PostGIS package have different maintainers, so offerings are not equivalent. Both versions generally have latest minor version of PostGIS, but versions of libraries used may be different, other PostGIS related extensions like pgRouting, postgis_sfcgal are packaged with the windows but not OSX version.

Additional Install Guides

Getting Started

In order to use PostGIS you first need to install the binaries. You can install these via package managers or compile PostGIS yourself.

Enabling PostGIS

PostGIS is an optional extension that must be enabled in each database you want to use it in before you can use it. Installing the software is just the first step. DO NOT INSTALL it in the database called postgres.

Connect to your database with psql or PgAdmin. Run the following SQL. You need only install the features you want:

 1-- Enable PostGIS (as of 3.0 contains just geometry/geography)
 2CREATE EXTENSION postgis;
 3-- enable raster support (for 3+)
 4CREATE EXTENSION postgis_raster;
 5-- Enable Topology
 6CREATE EXTENSION postgis_topology;
 7-- Enable PostGIS Advanced 3D
 8-- and other geoprocessing algorithms
 9-- sfcgal not available with all distributions
10CREATE EXTENSION postgis_sfcgal;
11-- fuzzy matching needed for Tiger
12CREATE EXTENSION fuzzystrmatch;
13-- rule based standardizer
14CREATE EXTENSION address_standardizer;
15-- example rule data set
16CREATE EXTENSION address_standardizer_data_us;
17-- Enable US Tiger Geocoder
18CREATE EXTENSION postgis_tiger_geocoder;

Upgrading PostGIS

To upgrade PostGIS, you first have to install the latest binaries and then upgrade each database you have PostGIS installed in

For example connect to database you want to upgrade and if you just installed binaries for 2.1.3 You can upgrade from 2.0 to 2.1, 2.2 et.c using this approach. To go from 1.* to 2.* you need to do a hard upgrade. Refer to PostGIS install for more extensive instructions. Note: that as of PostGIS 2.1.3 and PostGIS 2.0.6, you need to set environment variables to get full features.

1-- Upgrade PostGIS (includes raster) to latest version
2ALTER EXTENSION postgis UPDATE;
3ALTER EXTENSION postgis_topology UPDATE;

or to a specific version

 1-- Upgrade PostGIS (includes raster)
 2ALTER EXTENSION postgis
 3 UPDATE TO "3.2.1";
 4-- Upgrade Topology
 5ALTER EXTENSION postgis_topology
 6 UPDATE TO "3.2.1";
 7
 8-- Upgrade US Tiger Geocoder
 9ALTER EXTENSION postgis_tiger_geocoder
10 UPDATE TO "3.2.1";

Spatial SQL

See the documentation for more guidance.

 1-- Create table with spatial column
 2CREATE TABLE mytable (
 3  id SERIAL PRIMARY KEY,
 4  geom GEOMETRY(Point, 26910),
 5  name VARCHAR(128)
 6);
 7
 8-- Add a spatial index
 9CREATE INDEX mytable_gix
10  ON mytable
11  USING GIST (geom);
12
13-- Add a point
14INSERT INTO mytable (geom) VALUES (
15  ST_GeomFromText('POINT(0 0)', 26910)
16);
17
18-- Query for nearby points
19SELECT id, name
20FROM mytable
21WHERE ST_DWithin(
22  geom,
23  ST_GeomFromText('POINT(0 0)', 26910),
24  1000
25);