What is the easiest way to install PostGIS?

What is the easiest way to install postgis on Ubuntu Server 11.10?

apt-get install ...

Solution 1:

this package is not available in the official repository so you can use a ppa for a quick and dirty installation.

https://wiki.ubuntu.com/UbuntuGIS

for Ubuntu 11.10 Oneiric the packages are only available in the unstable version of this PPA, to install and use this ppa

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable

to update your software list and install the package you are interested of

sudo apt-get update; sudo apt-get install postgis

Solution 2:

As noted in Micro's answer, your best bet for installing PostGIS is the UbuntuGIS PPA. As of the time I'm writing they are distributing PostgreSQL 9.1 and PostGIS 2.0.1. Starting with these versions it became much easier to set up a PostGIS database.

Once PostGIS is installed, how do you create a PostGIS database? Ignore any old docs you find about using template_postgis or importing a bunch of .sql scripts in to your database. All you need to do in the new way is

createdb foo
psql -d foo -c 'create extension postgis'
psql -d foo -c 'create extension postgis_topology'