= How to install PostGIS 2.0 on Debian 7.x (''wheezy'') from source = == Prerequisites == Several components are needed, which can either be built from source or installed from pre-built packages, as shown below. It is assumed you have already installed and configured `sudo` (not done by default). Install prerequisite packages using: {{{ sudo apt-get install build-essential postgresql-9.1 postgresql-server-dev-9.1 libxml2-dev libgeos-dev libproj-dev libjson0-dev xsltproc docbook-xsl docbook-mathml }}} Optional package for raster support (recommended): {{{ sudo apt-get install libgdal-dev }}} == Build PostGIS == {{{ wget http://download.osgeo.org/postgis/source/postgis-2.0.3.tar.gz tar xfvz postgis-2.0.3.tar.gz cd postgis-2.0.3 }}} PostGIS 2.0 can be configured to disable topology or raster extensions, using the configure flags `--without-raster` and `--without-topology`. The default is to build both extensions: {{{ ./configure make sudo make install sudo ldconfig sudo make comments-install }}} Lastly, enable the command-line tools to work from your shell: {{{ sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/raster2pgsql }}} === PostGIS Extension for PostgreSQL === Spatially enabling a database using extensions is a new feature of PostgreSQL 9.1. Connect to your database using pgAdmin or psql, and run the following commands. To add postgis with raster support: {{{ CREATE EXTENSION postgis; }}} To add topology support, a second extension can be created on the database: {{{ CREATE EXTENSION postgis_topology; }}} === Enabler Scripts / Template === Enabler scripts can be used to either build a template, or directly spatially enable a database. This method is older than the extension method, but is required if the raster support is not built. The following example creates a template, which can be re-used for creating multiple spatially-enabled databases. Or if you just want to make one spatially enabled database, you can modify the commands for your needs. PostGIS: {{{ sudo -u postgres createdb template_postgis sudo -u postgres psql -d template_postgis -c "UPDATE pg_database SET datistemplate=true WHERE datname='template_postgis'" sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis.sql sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/spatial_ref_sys.sql sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis_comments.sql }}} with raster support: {{{ sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/rtpostgis.sql sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/raster_comments.sql }}} with topology support: {{{ sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology.sql sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology_comments.sql }}}