Posted by Steve on Wed 6 Jul 2005 at 14:08
There are times when a package upon your Debian system needs reinstalling to fix problems which you might have caused, or to revert back to a pristine state.
Reinstalling packages is generally a simple job. There is a nice shortcut for the apt-get command which can be used to reinstall a package - the --reinstall flag.
If that isn't sufficient you can remove, or purge, the installed package and then simply re-install it.
As a simple example I recently needed to reinstall my apache2-common package - because I'd been editing one of the loadable modules with a hex editor, to change it's behaviour. (Long story ;)
Initially I intended to simply purge the package by running:
dpkg --purge apache2-common
However this immediately complained that several packages required it's presense:
root@mystery:~# dpkg --purge apache2-common dpkg: dependency problems prevent removal of apache2-common: apache2-threaded-dev depends on apache2-common (= 2.0.54-4). apache2-mpm-prefork depends on apache2-common (= 2.0.54-4). dpkg: error processing apache2-common (--purge): dependency problems - not removing Errors were encountered while processing: apache2-common
To fix this you can either attempt to reinstall, or break the dependencies manually.
After deleting the module which I'd been editing, I simply used the --reinstall flag to fix the mess:
root@mystery:~# rm /usr/lib/apache2/modules/mod_include.so root@mystery:~# apt-get install --reinstall apache2-common Reading package lists... Done Building dependency tree... Done 0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 14 not upgraded. Need to get 0B/798kB of archives. After unpacking 0B of additional disk space will be used. Do you want to continue [Y/n]? Selecting previously deselected package apache2-common. (Reading database ... 68998 files and directories currently installed.) Preparing to replace apache2-common 2.0.54-4 (using .../apache2-common_2.0.54-4_i386.deb) ... Unpacking replacement apache2-common ... Setting up apache2-common (2.0.54-4) ...
Once this was done the package was reinstalled correctly, and the file I'd modified then deleted was back in place:
root@mystery:~# ls -l /usr/lib/apache2/modules/mod_include.so -rw-r--r-- 1 root root 36484 2005-05-12 06:36 /usr/lib/apache2/modules/mod_include.so
In some cases using the --reinstall flag isn't enough to fix problems. In that case perhaps the simplest solution is to temporarily break the system's deependencies.
For example we could have solved this problem by simply removing the apache2-common package - ignoring the fact that there are several installed packages which require it's presence.
To do this we use one of the dangerous options of dpkg:
root@mystery:~# dpkg --purge --force-depends apache2-common dpkg: apache2-common: dependency problems, but removing anyway as you request: apache2-threaded-dev depends on apache2-common (= 2.0.54-4). apache2-mpm-prefork depends on apache2-common (= 2.0.54-4). (Reading database ... 68998 files and directories currently installed.) Removing apache2-common ... Stopping web server: Apache2. Purging configuration files for apache2-common ... dpkg - warning: while removing apache2-common, directory `/etc/apache2/ssl' not empty so not removed. dpkg - warning: while removing apache2-common, directory `/etc/apache2/sites-enabled' not empty so not removed.
As you can see the usage of the --force-depends flag has turned what would previously have been a fatal error into a mere warning.
Once the package is out of the way it can be reinstalled which will stop the system from being in a broken state:
root@mystery:~# apt-get install apache2-common ...
There are other options you can use for dpkg to turn different errors into warnings, to see the list run "dpkg --force-help".
Hopefully you'll never be in a situation where you have to resort to these kind of tactics, but if you are don't panic. It's almost always possible to fix problems.