Saturday, November 22, 2008

When apt-get fails to reinstall a package

While experimenting with the Moin Moin Wiki, I got into some bother attempting to uninstall and reinstall it. The problem originated from me manually removing some configuration files. apt-get subsequently refused to reinstall those files. I eventually resolved by using dpkg.

I had initially followed the installation steps for Moin Moin on the Ubuntu Server Guide. So I had installed by doing
$ sudo apt-get install python-moinmoin
So to uninstall, I did
$ sudo apt-get remove python-moinmoin
I now know that that did not uninstall a base package, moinmoin-common, on which it depends. But I didn't notice that at first. All I saw was that some configuration files were still present in /etc/moin, so I rm -rf them.

And there began my trouble, because thereafter I could not get apt-get to delete or reinstall the configuration files to that dir.

I did various iterations of apt-get install, apt-get remove and apt-get purge for the moinmoin-common and python-moinmoin packages. But the remove operations never removed /etc/moin and the installs never installed the missing files.

I used dpkg-deb to inspect the moinmoin-common archive file in /var/cache/apt/archives. I could see the to files I wanted were in the archive. But I could not get them to unpack to /etc/moin.

A temporary workaround was to use dpkg-deb to extract the archive file to /tmp, which unpacked everything, and then manually copy the uninstallable files from there to /etc/moin. But I wanted to find the proper solution.

I found a thread on the Ubuntu Forums outlining an equivalent problem with an apache2 installation. The advice there was to use Synaptic to remove the package. I don't have that option as I am running a headless server and Synaptic is a GUI tool. But at least there was the suggestion of a solution. If it can be done in a Debian/Ubuntu GUI, then be sure it can be done on the command line too.

Then I found a good article at Linux.com which explained how you can escalate from apt-get to dpkg to resolve package management problems.

So the happy ending was to do
$ sudo dpkg --purge moinmoin-common
This removed the troublesome files and the references to them that the package manager was evidently keeping. After that, I was able to cleanly reinstall Moin Moin.

No comments:

Post a Comment