Reinstalling packages to fix problems.

Posted by Steve on Wed 6 Jul 2005 at 14:08

Tags: none.

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.

 

 


Posted by Anonymous (194.47.xx.xx) on Wed 6 Jul 2005 at 14:43
apt-get? Don’t you mean “aptitude reinstall ”?

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Wed 6 Jul 2005 at 14:48
[ View Steve's Scratchpad | View Weblogs ]

Old habits die hard ... *shrugs*

aptitude works as well, I just always forget to mention it.

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Anonymous (50.161.xx.xx) on Sun 23 Mar 2014 at 11:09
I've been running Debian since 3.0 and never use aptitude.

[ Parent | Reply to this comment ]

Posted by Anonymous (82.119.xx.xx) on Wed 6 Jul 2005 at 18:58
Thanks for this article. I needed it before few days when I accidentally deleted some files. But I have found my (of course not so elegant) solution - download that package using links/wget and install it using dpkg -i.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Wed 6 Jul 2005 at 19:12
[ View Steve's Scratchpad | View Weblogs ]

You might find this piece on working with Debian binary packages useful - if you just need to unpack a file or two..

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Anonymous (70.112.xx.xx) on Thu 7 Jul 2005 at 05:27
Also useful if you're worried someone's put some malicious binaries somewhere on your system... it's unlikely they hacked apt-get or dpkg, which would be the only real way to keep their bad bins from being overwritten.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Thu 7 Jul 2005 at 12:20
[ View Steve's Scratchpad | View Weblogs ]

For that you really want to use integrit / tripwire.

If the kernel, or a kernel module, has been replaced you cannot trust anything on the system, not even "known good" binaries. The system-calls could easily be modified by a rootkit so that the binaries do not tell you what is really happening on the system.

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Anonymous (83.239.xx.xx) on Sun 22 Jul 2007 at 18:36
Quite an old article, but here is the addition: what if you want to reinstall ALL packages - here is the answer

aptitude reinstall '~i'

where '~i' means all installed packages. see aptitude reference manual for more search patterns.

[ Parent | Reply to this comment ]

Posted by Anonymous (62.163.xx.xx) on Sun 1 Mar 2009 at 21:00
tnx man! you've just made my day!

[ Parent | Reply to this comment ]

Posted by Anonymous (81.190.xx.xx) on Sun 13 Oct 2013 at 10:50
"--force-depends" is now "--ignore-depends"

[ Parent | Reply to this comment ]

Posted by Anonymous (81.190.xx.xx) on Sun 13 Oct 2013 at 10:51
"--force-depends" is now "--ignore-depends"

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 464 votes ~ 5 comments )