Broken packages and unmet dependency installation QGIS, PostgreSQL and postgis Ubuntu 14.04

I had faced a similar problem installing qgis. I finally got it installed using aptitude package manager.

Try this first:

sudo apt-get update then sudo apt-get -f install.

If that doesn't work try the higher level package manager aptitude.

sudo aptitude install qgis python-qgis qgis-plugin-grass

It gives multiple solutions like this and you can select one.

Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:

      Downgrade the following packages:                                                                    
1)      libqt4-declarative [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]
2)      libqt4-network [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]    
3)      libqt4-opengl [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]     
4)      libqt4-script [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]     
5)      libqt4-sql [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]        
6)      libqt4-sql-sqlite [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)] 
7)      libqt4-svg [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]        
8)      libqt4-xml [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]        
9)      libqt4-xmlpatterns [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]
10)     libqtcore4 [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]        
11)     libqtdbus4 [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]        
12)     libqtgui4 [4:4.8.7+dfsg-7ubuntu1~xenialoverlay1~1 (now) -> 4:4.8.7+dfsg-5ubuntu2 (xenial)]         


Accept this solution? [Y/n/q/?] y
The following packages will be DOWNGRADED:
  libqt4-declarative libqt4-network libqt4-opengl libqt4-script libqt4-sql libqt4-sql-sqlite libqt4-svg libqt4-xml libqt4-xmlpatterns libqtcore4 libqtdbus4 libqtgui4 
The following NEW packages will be installed:
  libdrm-dev{a} libfcgi0ldbl{a} libgl1-mesa-dev{a} libglade2-0{a} libglu1-mesa-dev{a} libjs-jquery-ui{a} libjs-leaflet{a} liblwgeom-dev{a} libqca2{a} libqca2-plugin-ossl{a} libqca2-plugins{a} 
  libqgis-analysis2.18.3{a} libqgis-app2.18.3{a} libqgis-core2.18.3{a} libqgis-customwidgets{a} libqgis-gui2.18.3{a} libqgis-networkanalysis2.18.3{a} libqgis-server2.18.3{a} libqgisgrass7-2.18.3{a} 
  libqgispython2.18.3{a} libqjson0{a} libqt4-dbus{a} libqt4-designer{a} libqt4-dev{a} libqt4-dev-bin{a} libqt4-help{a} libqt4-opengl-dev{a} libqt4-qt3support{a} libqt4-scripttools{a} libqt4-test{a} 
  libqtassistantclient4{a} libqwt5-qt4{a} libspatialindex4v5{a} libx11-xcb-dev{a} libxcb-dri2-0-dev{a} libxcb-dri3-dev{a} libxcb-glx0-dev{a} libxcb-present-dev{a} libxcb-randr0-dev{a} libxcb-render0-dev{a} 
  libxcb-shape0-dev{a} libxcb-sync-dev{a} libxcb-xfixes0-dev{a} libxdamage-dev{a} libxext-dev{a} libxfixes-dev{a} libxshmfence-dev{a} libxxf86vm-dev{a} mesa-common-dev{a} python-cycler{a} python-dateutil{a} 
  python-future{a} python-gdal{a} python-glade2{a} python-httplib2{a} python-jinja2{a} python-markupsafe{a} python-matplotlib{a} python-matplotlib-data{a} python-pygments{a} python-pyparsing{a} 
  python-pyspatialite{a} python-qgis python-qgis-common{a} python-qscintilla2{a} python-qt4{a} python-qt4-sql{a} python-shapely{a} python-sip{a} python-tz{a} python-yaml{a} qdbus{a} qgis qgis-common{a} 
  qgis-plugin-grass qgis-plugin-grass-common{a} qgis-provider-grass{a} qgis-providers{a} qgis-providers-common{a} qt4-designer{a} qt4-linguist-tools{a} qt4-qmake{a} x11proto-damage-dev{a} 
  x11proto-dri2-dev{a} x11proto-fixes-dev{a} x11proto-gl-dev{a} x11proto-xext-dev{a} x11proto-xf86vidmode-dev{a} 
The following packages are RECOMMENDED but will NOT be installed:
  qt-at-spi 
0 packages upgraded, 88 newly installed, 12 downgraded, 0 to remove and 57 not upgraded.

I encountered similar problems when updating from QGIS 2.16 to 2.18.

Try this workaround, that finally worked for me:

In the error message, look out for the lines

Depends: ... but it is not installable

Before installing qgis, you may need to install those packages manually one by one. If they install, try again to install QGIS, with some or all broken dependencies solved.

It might help to stick to the debian or ubuntugis repo, but avoid to install packages from both.

In my case, it was gdal that blocked the proper installation of QGIS.


UPDATE from comments

It seems that GDAL version conflicts avoid the proper installation.

According to http://postgis.net/install/ you have three choices for Postgis on Ubuntu:

  • Ubuntugis

This gives you postgis 2.2 compiled for Postgres 9.3. You can get QGIS 2.14.3 from the same repo, or use http://qgis.org/ubuntugis for QGIS 2.18.0 or 2.14.8. You will get GDAL 2.1.0 with that. This seems to be the best choice currently.

  • PostgreSQL Apt Repo

The one you used, but not compatible with QGIS from ubuntugis.

  • Debiangis

They offer Postgis 2.1.4, 2.2.2 and 2.3.0. You can get QGIS LTR from there too, or use http://qgis.org/debian for 2.18.0, compiled against GDAL 1.10 for trusty and GDAL 1.11.3 for xenial.

  • Another choice are the default Ubuntu packages

They offer Postgis 2.1.2 for Postgres 9,3, built with libgdal1h (GDAL 1.10.1) for trusty. The xenial package is Postgis 2.2.1 compiled against libgdal1i (GDAL 1.11.3). If you install QGIS from http://qgis.org/debian or http://qgis.org/debian-ltr, you get QGIS 2.18.0 or 2.14.8 compiled against the same GDAL versions for trusty and xenial.

You get broken dependencies if you try to combine packages from different sources, so DON'T DO IT.


The following worked for me on Ubuntu 16.04 and QGIS 2.18:

sudo apt remove *qgis*
sudo apt purge *qgis*

Then:

sudo apt update
sudo apt install qgis python-qgis