Testing PostGIS 2.0 in Ubuntu

With PostgreSQL’s introduction of K-Nearest Neighbor searches in version 9.1, it was only a matter of time until PostGIS implemented GiST idexes for its own data types.  That time has come with its upcoming 2.0 release.  If you’ve got a twitch and want to set it up today, here’s how to get started. (A great many thanks to the manual which got me a large part of the way there)

Start with a vanilla installation of Ubuntu Server (I’m using version 11.10)

EDIT 28 February 2012: Link to current snapshot updated.

EDIT 29 February 2012: Added GDAL library dependency.

First, make sure we have the necessary tools installed

sudo apt-get install build-essential autoconf libtool gettext libxml2-dev libgeos-dev libgdal1-dev proj subversion

Install PostgreSQL 9.1

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

Normally I would want to get the sources directly from the SVN repository, but I was having trouble building from there. There are snapshots available, however, so lets grab that and use it.

wget http://postgis.refractions.net/download/postgis-2.0.0alpha7SVN.tar.gz
tar -zxvf postgis-2.0.0alpha7SVN.tar.gz

Now lets navigate into the folder so we can build and install PostGIS

cd postgis-2.0.0SVN
sudo make install

Congratulations, PostGIS 2.0 is now installed!

And a quick refresher on setting up a PostGIS database:

sudo su postgres
postgres=# create role myuser with createdb superuser login password 'mypassword';
postgres=# \q
createdb testdb
psql -d testdb -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis.sql -v ON_ERROR_STOP=1
psql -d testdb -f /usr/share/postgresql/9.1/contrib/postgis-2.0/spatial_ref_sys.sql -v ON_ERROR_STOP=1


  1. Anonymous Postger December 10, 2011

    Man thanks so much for this tutorial…
    Keep it up

  2. Regie January 14, 2012

    Great tutorial. One question/request though: how do you add raster support to Postgis 2.0. I tried adding in –with-raster after ./configure but it never worked.

  3. Rick Wayne May 10, 2012

    I ran into errors when I tried to source postgis.sql:
    ERROR: could not load library “/usr/lib/postgresql/9.1/lib/postgis-2.0.so”: /usr/lib/postgresql/9.1/lib/postgis-2.0.so: undefined symbol: GEOSRelatePatternMatch

    Turned out I needed to run (via sudo or as root) “ldconfig”. Magically fixed it.

Leave a Reply