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
./configure
make
sudo make install

Congratulations, PostGIS 2.0 is now installed!

And a quick refresher on setting up a PostGIS database:

sudo su postgres
psql
postgres=# create role myuser with createdb superuser login password 'mypassword';
postgres=# \q
exit
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
gis

Comments