[GIS] Install Postgis in Ubuntu 16.04 in with already postgresql 9.3 installed

postgispostgresqlUbuntu

In ubuntu 16.04 with postgresql 9.3 when I tried to install postgis with using command

sudo apt-get install postgis postgresql-9.3-postgis-2.1

It installed postgresql 9.6 and postgis-9.6 version. And when tried to create extension it gives error

CREATE EXTENSION postgis;
ERROR: could not open extension control file "/usr/share/postgresql/9.3/extension/postgis.control": No such file or directory.

Also two servers are running

postgres@db:~$ psql
psql (9.6.3, server 9.3.17)
Type "help" for help.

Best Answer

You explicitely installed Version 9.3 and implicitely installed 9.6 as thepostgis package depends on it. But I don't know why you're missing the postgis extension files for 9.3 then.

You can list dependencies of a package:

sudo apt-cache depends postgis

Installing just postgis should be enough.


Fix by uninstalling older Version:

Remove version 9.3:

sudo apt-get purge postgresql-9.3-postgis-2.1 postgresql-9.3

Keeping multiple PostgreSQL installations; How to use a specific version:

When multiple versions are installed, a new PostgreSQL cluster is used for each. You need to specify a cluster when using psql:

psql --cluster 9.6/main -d "YOUR_DATABASE" -c "CREATE EXTENSION postgis;"

List available clusters:

pg_lsclusters