[GIS] How to install PostgreSQL + PostGIS + MapServer + Python-MapScript on Ubuntu 12.04 LTS w/o compiling from source

installationmapscriptmapserverpostgisUbuntu

This question is similar to How to have PostGIS 2.1 and the Python osgeo library installed together without compiling from source?

but I couldn't figure out how to ask a follow-up question.

I am trying to get PostgreSQL + PostGIS + MapServer + Python-MapScript working on Ubuntu 12.04 LTS, for a Geo-Django site. In the past, this has worked wonderfully (was still working in April of 2014), however something has changed, and I'm now getting an error regarding gdal compatibility:

The following packages have unmet dependencies: postgresql-9.1-postgis : Depends: libgdal1 (>= 1.9.0) but it is not going to be installed E: Unable to correct problems, you have held broken packages.

After a fair bit of searching, I came across Brian (cokrzys)'s answer to the post above. I followed his instructions on a clean install of Ubuntu 12.04, and was subsequently able to create the PostGIS templates in PostgreSQL 9.3. However, when I then try to install python-mapscript, I get the following message:

The following packages will be REMOVED:
libgdal1 postgis postgresql-9.3-postgis-2.1

So, the problem is that it does not appear that I can have both the postgis libraries and the python-mapscript libraries installed at the same time.

Honestly, I don't care what version of PostgreSQL / PostGIS / MapServer I use, so long as I can get it running on Ubuntu 12.04.

Has anyone had any luck with this?


@Mark helped me to finally got this working as follows:

#!/usr/bin/env bash
###################################################################
# Install GDAL, MapServer, etc. first
###################################################################
echo "Y" | sudo apt-get install python-software-properties
echo "Y" | sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
echo "Y" | sudo apt-get install mapserver-bin
echo "Y" | sudo apt-get install gdal-bin
echo "Y" | sudo apt-get install cgi-mapserver
echo "Y" | sudo apt-get install python-gdal
echo "Y" | sudo apt-get install python-mapscript
echo "Y" | sudo apt-get install python-gdal

###################################################################
# Then Install PostgreSQL9.1, PostGIS 9.1
###################################################################
echo "Y" | sudo apt-get install postgresql-9.1
echo "Y" | sudo apt-get install postgresql-client-9.1
echo "Y" | sudo apt-get install postgresql-server-dev-9.1
echo "Y" | sudo apt-get install postgresql-plperl-9.1
echo "Y" | sudo apt-get install postgresql-9.1-postgis-2.0

Best Answer

From a clean Ubuntu 12.04 Precise install I was able to get it to work with this:

echo 'deb http://ppa.launchpad.net/ubuntugis/ppa/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
echo 'deb-src http://ppa.launchpad.net/ubuntugis/ppa/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 314DF160
sudo apt-get update
sudo apt-get install -y postgresql-server-dev-9.1 postgis python-mapscript python-gdal

For more up-to-date gis packages use the unstable repository

echo 'deb http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu precise main' | sudo tee -a /etc/apt/sources.list
echo 'deb-src http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu precise main' | sudo tee -a /etc/apt/sources.list

This also works for Ubuntu 14.04 Trusty, just replace precise with trusty when adding the ubuntugis repos. Then you can also install postgres 9.3 instead of 9.1. So on Trusty use:

sudo apt-get install -y postgresql-server-dev-9.3 postgis python-mapscript python-gdal

The two references for installing this I used were

http://trac.osgeo.org/ubuntugis/wiki/UbuntuGISRepository

https://launchpad.net/~ubuntugis/+archive/ubuntu/ppa/

Also, if you want to use the postgis raster driver through mapscript, it is worth trying to install the latest GDAL version, as it has essential improvements on the raster driver (its much faster and more stable). So in that case I would recommend the unstable repo, in my work so far I did not run into problems due to the "unstable" name.