Monday, April 7, 2014

Resolve broken dependency on Ubuntu

It happens at times that there is a broken package dependency stopping apt-get command from functioning properly. E.g., I recently encountered an error when running 'apt-get upgrade' on my Ubuntu 12.04 machine:

The following packages have unmet dependencies.
 libavahi-common3 : Depends: libavahi-common-data but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)


Running 'apt-get -f install' turned out no good:

dpkg: error processing libavahi-common-data (--configure):
 libavahi-common-data:amd64 0.6.30-5ubuntu2 cannot be configured because libavahi-common-data:i386 is in a different version (0.6.30-5ubuntu2.1)

'apt-get remove libavahi-common-data' did not work because of the same stupid dependency problem. After trying various approaches, I finally got the following solution:

sudo dpkg --force-all -P libavahi-common-data:i386 libavahi-common-data
The above command would force remove the two broken packages and hence fix the broken dependency. Now we can run apt-get command to install whatever we want.