For sudo and root users: Dealing with Apt and dpkg errors

Having just experienced a total website crash due to a failed upgrade it is only in place to talk about some of the common errors of apt and dpkg and how to fix them – so that the system can possibly recover from some serious crashes.

Using – -force-overwrite (Note. There should be no space between – – )

Sometimes when you build your own custom Debian packages you might encounter something like:

Errors were encountered while processing:

trying to overwrite ‘/usr/sbin/synaptic’, which is also in package synaptic 0.81.2
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

What is happening on the above examples is that your custom package is trying to overwrite something, which is already being used by another program that has
been installed to the system. Now, notice that the above errors only appear if your custom package is named differently than the already installed one. For example.
Synaptic version 1 will get replaced by Synaptic version 2 without any problems but Synaptic version 2 cannot automatically replace a program called Synaptic-custom version 1.

If you do want to install your custom package you can apply force into it, which means that it will ignore the complaints made by the already installed package

An example.

dpkg -i – -force-overwrite /var/cache/apt/archives/evince_3.12.2-1_i386.deb

When using – -force-overwrite you should be cautious since it can lead to some very bad results and even to a completely broken system. The rule I have lived by is
that I never overwrite anything essential (libc6, kernel etc.) since if the system can run without a program x there should not be no harm done if something
breaks momentarily.

Missing dependencies:

Now, since you are installing your custom package (with dpkg -i something) everything seems to go smoothly until you get complaints about missing dependencies and everything ends with a series
of error messages. What apt is actually trying to say to you is: I cannot find a package you are trying to install from the repositories on /etc/apt/sources.list but it seems your package needs dependencies x,y,z…

So in other words: since your package is being installed from your computer and not from an apt repository apt-get will not go forward automatically. To solve the previous issue execute apt-get -f install (or create a Debian repository)

With apt-get -f install apt-get will fetch the missing dependencies along with finalizing your previously halted installation.

Packages x and y have insuffient dependencies and will be removed:

You may encounter something like the above when you are upgrading your system from Debian Stable to Debian Testing. Debian Testing usually has some migration issues,
which means that the specific additional package, which is being used by your custom compiled program might not available yet and hence comes the removal request.
For more about Differences among Debian branches:

Upgrading to Debian Testing issue: Cannot configure grub-pc while upgrading. Nothing helps even apt-get -f install fails:

Solution: Just do apt-get remove grub-pc

Also, just in case do update-grub to make sure that your grub entries can still be updated correctly.