Thursday, October 4, 2012

unmet dependencies in aptitude: when all else fails

A routine update of system packages on 12.04 failed with errors of a broken package due to unmet dependencies. I upgraded from 10.04 to 12.04 a month ago, and things have been working relatively well since then, but somehow something broke in postgresql:

dpkg: dependency problems prevent configuration of postgresql-9.1:
 postgresql-client-9.1 (9.1.6-0ubuntu12.04) breaks postgresql-9.1 (<< 9.1.6-0ubuntu12.04) and is installed.
  Version of postgresql-9.1 to be configured is 9.1.5-1~lucid3.
dpkg: error processing postgresql-9.1 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 postgresql-9.1
E: Sub-process /usr/bin/dpkg returned an error code (1)

So I tried to fix this with all the tools I was aware of, but to no avail, and then finally gave up and decided to postgresql altogether since I didn't need it right now.

enkomion [19:14:55] ~ $ sudo apt-get purge postgresql-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 postgresql-9.1 : Depends: postgresql-common (>= 115~) but it is not going to be installed
 postgresql-client-9.1 : Breaks: postgresql-9.1 (< 9.1.6-0ubuntu12.04) but 9.1.5-1~lucid3 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).


enkomion [19:15:07] ~ $ sudo apt-get install -f 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  libutouch-evemu1 libutouch-geis1 libutouch-frame1 libutouch-grail1 libtrove-java
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  postgresql-9.1
Suggested packages:
  oidentd ident-server locales-all
The following packages will be upgraded:
  postgresql-9.1
1 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
1 not fully installed or removed.
Need to get 0 B/4,298 kB of archives.
After this operation, 5,915 kB disk space will be freed.
Do you want to continue [Y/n]? Y
dpkg: dependency problems prevent configuration of postgresql-9.1:
 postgresql-client-9.1 (9.1.6-0ubuntu12.04) breaks postgresql-9.1 (<< 9.1.6-0ubuntu12.04) and is installed.
  Version of postgresql-9.1 to be configured is 9.1.5-1~lucid3.
dpkg: error processing postgresql-9.1 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 postgresql-9.1
E: Sub-process /usr/bin/dpkg returned an error code (1)


Even the usual "sudo apt-get update" and manually trying to do "sudo apt-get purge postgresql*" didn't work.
dpkg: dependency problems prevent configuration of postgresql-9.1:
 postgresql-client-9.1 (9.1.6-0ubuntu12.04) breaks postgresql-9.1 (<< 9.1.6-0ubuntu12.04) and is installed.
  Version of postgresql-9.1 to be configured is 9.1.5-1~lucid3.
dpkg: error processing postgresql-9.1 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 postgresql-9.1
E: Sub-process /usr/bin/dpkg returned an error code (1)

I was frustrated with trying to fix this manually, and just wanted to get rid of all postgresql* packages altogether from my system. But even this wasn't happening via aptitude, and was becoming increasingly painful. Finally found the solution at http://dabase.com/e/01169/ which saved the day.


enkomion [19:20:10] ~ $ sudo dpkg --force-depends --purge postgresql*
(Reading database ... 361318 files and directories currently installed.)
Removing postgresql-server-dev-9.0 ...
Removing postgresql-client-9.0 ...
Removing postgresql-client-8.4 ...
Removing postgresql-client ...
Removing postgresql ...
Removing postgresql-common ...
 * No PostgreSQL clusters exist; see "man pg_createcluster"
Removing 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Purging configuration files for postgresql-common ...
dpkg: warning: while removing postgresql-common, directory '/var/lib/postgresql' not empty so not removed.
Removing postgresql-client-9.1 ...
Removing postgresql-client-common ...
Purging configuration files for postgresql-client-common ...
Processing triggers for ureadahead ...
Processing triggers for man-db ...

enkomion [19:34:30] ~ $ sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libutouch-evemu1 libutouch-geis1 libutouch-frame1 libutouch-grail1 libtrove-java
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.


All postgresql* packages finally removed without fuss :)

 So this is the solution for forcefully removing broken packages:

dpkg --force-depends --purge java-gcj-compat-dev
apt-get -f install