2016-11-18

apt-get: Package is in a very bad inconsistent state problem

After I dist-upgrade the Kubuntu 14.04 to 16.04, I ran the following command to update the system state.

  sudo apt-get update; sudo apt-get upgrade; sudo apt-get autoremove;

Then, I got the following error.

 dpkg: error processing gcc-doc (--remove):
 Package is in a very bad inconsistent state - you should
 reinstall it before attempting a removal.
 Errors were encountered while processing:
  gcc-doc
 E: Sub-process /usr/bin/dpkg returned an error code (1)

All the following attempt didn't work

 sudo dpkg --remove --force-remove-reinstreq gcc-doc
 sudo dpkg --configure -a
 sudo apt-get clean
 sudo apt-get autoclean

At the end, I did a brute force way.

Find gcc-doc related files in /var/lib/dpkg/info and remove them

 find /var/lib/dpkg/info/ -name *gcc-doc* -print | xargs rm

Then,

 sudo apt-get update; sudo apt-get upgrade;
 sudo apt-get install gcc-doc

This worked, but it is now by apt-get/dpkg and has some risk. Please use this with your own risk if you could not find any other solution.

No comments: