Package Management – How to Fix Half Installed Package Nightmare

aptdpkgpackage-managementsoftware installation

At some point, one of my servers stopped writing to its network attached storage device (I presume), and it resulted in a week or more's worth of packages ending up in the "half-installed" state.

What is odd is that apt-get does not report any issues and I was able to get the most recent updates to install as intended.

It was only when I took a look through the logs (dpkg.log*) and found that there was many more packages in this state.

I need a way to go through all of the packages in apt-get or dpkg, and perform an apt-get install <packagename> --reinstall operation.

Unless there is another way to clean up this mess.

Does anybody have any idea on how I can do this? or have any other ideas on how to resolve this issue?

Best Answer

Try sudo dpkg --configure -a. That should automatically repair those packages.

If that doesn't work, try running sudo apt-get install -f and then running sudo dpkg --configure -a again

If you really want to go through each package and reinstall,

And keep in mind, this is definitely not the ideal solution.

Only do this if the sudo dpkg --configure -a command does not work.

This will take a really, really long time since it has to download all the packages again and install them:

for pkg in `dpkg --get-selections | awk '{print $1}' | egrep -v '(dpkg|apt|mysql|mythtv)'` ; do apt-get -y --force-yes install --reinstall $pkg ; done

Source