How to fix broken packages on Ubuntu

Solution 1:

What happened here is that the post-install script of the libpaper1 package was broken, and exited with an error during the install process. This should not happen, because it breaks the package state just as you experienced, which is why it is a good idea to report the error to the package maintainer. See the ReportingBugs wiki page for details.

Your options are the following:

Remove the package and wait for a fix. This is what probably happened in your case: by the time you decided to purge the libpaper1 package, it got fixed, and the new install succeeded.

It should be noted that no matter if there is an upgraded package available, it will not be downloaded while the package state is broken. So you have to remove the package, and reinstall it.

Repair the post-install script. This is an alternative if you really, absolutely need that package, and you don't want to wait until a fix. You really need to know what you're doing (shell programming knowledge is a must), but repairing the script is usually straightforward.

Every package can have a pre-installation and a post-installation script, these dwell in the /var/lib/dpkg/info directory, and are named package[:arch].preinst and package[:arch].postinst. These are executed prior to, and after the installation, respectively [*].

In your case the post-installation script failed, which means that the package got installed (so the files was extracted), the only thing left was to execute the post-install script. So what you need to do is to run the script (libpaper1:amd64.postinst) from a root terminal, and record the line in which the error occurred. Repairing the script is usually trivial from here, but be sure to understand what the script was trying to do, since it may be possible that the failed command was crucial for the package. Do try to actually repair the script (for example, appending || true to the end of the line works, but may not be the best idea).

If the script runs without error, the

dpkg --configure -a

command will configure all pending packages, and runs the postinstall script in the process, restoring the package state.

[*] The actual process is a little bit more complicated of course; if you want to know what happens exactly during install/removal, see the description of the install, configure, and remove actions in the dpkg(1) man page.

Solution 2:

Did you try apt-get install -f?

I already had such problems when I had to work on servers with different package sources.

The solutions were different. In general, you should avoid mixing different package sources.

If packages with the apt parameter -t <...> were installed, then it helped to install all problematic packages with the help of this parameter.

Sometimes, however, I had to remove the packages first.

But I also had the case that I had to work with -Force parameters.Did you try apt-get install -f?