Correcting Broken Packages

For these first two steps, many people have better results with ‘aptitude’ finding a resolution. This command may help, but it is not installed by default in Devuan. If you recall it and install it after the broken package situation is resolved, it is worth trying.

*PACKAGE* is meant to be a package name that is broken. Replace a package name when using the commands.

Step one:

   sudo apt-get update –fix-missing
   sudo dpkg –configure -a
   sudo apt-get install -f

Step two:

   sudo dpkg --configure -a
   sudo apt-get clean
   sudo apt-get update

you may need to delete the lock files. Lock files are used to keep resources available for certain programs – it helps prevent other programs from accessing files at the same time. This can be done by simply deleting the lockfile list:

   sudo rm /var/lib/apt/lists/lock

Step three:

   sudo apt-get remove PACKAGE

It probably won’t be successful, but it is worth trying before removing it forcefully.

Depending on the errors you get when trying to remove the package normally, you might be able to identify the broken package using dpkg and grep:

   dpkg -l | grep ^..r

This command lists all packages, then grep lists any results containing the ‘r’ flag in the third field, which means “reinst-required” (reinstall required). If the broken package shows up, you will be able to remove it.

Execute the following command to forcefully remove the package from your machine. Don’t forget to enter your password to authorize the deletion. Replace with the name of the broken package.

   sudo dpkg --remove --force-remove-reinstreq PACKAGE
   sudo apt-get clean
   sudo apt-get update

After that, try to install the package from scratch. It should install normally now.

Last try step:

This pair of commands will remove the packages scripts to be performed before and after installation/removal of a package, then remove it from the database of installed packages.

   mv /var/lib/dpkg/info/PACKAGE.* /tmp/
   dpkg --remove --force-remove-reinstreq PACKAGE

Source: http://www.piprime.fr/1480/manually-remove-broken-package-debian-ubuntu/

Source: http://www.iasptk.com/ubuntu-fix-broken-package-best-solution/

Source: https://www.rosehosting.com/blog/how-to-fix-broken-packages-on-ubuntu-16-04-and-debian-9/