Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I killed by mistake a dpkg process running in the background and I would like to reinstall all packages to be sure everything is allright.

First, I tried to get a list of all packages and reinstall them

dpkg --get-selections | grep -v deinstall | awk '{print $1}' > list.log
apt-get install --reinstall $(cat list.log)

But there are messages like :

E: Couldn't configure pre-depend debconf:i386 for console-setup:i386, probably a dependency cycle.

I tried apt-get -f install, without success.

As a last resort, I reinstalled all programs which failed the checksums :

dpkg -l | grep ^ii | awk '{ print $2 }' | xargs debsums -s -a

What should I do to reinstall everything ?

Edit : Problem solved. The issue was something else (see the comments). I understand it's something to avoid with Debian though.

share|improve this question
I recently had a crash while trying to install a package. When I rebooted and tried to reinstall that package, I received the message, "E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.". Running that command removed said package and it configuration files. I was then able to install the package from scratch. Try giving that command a go. – embedded.kyle Jun 12 '13 at 12:32
It didn't do anything, so I guess nothing is broken. I will try later to check if my driver issues are solved. – alex_reader Jun 12 '13 at 13:01
Reinstalling all packages == really bad idea. (a) It's almost always unnecessary (b) it will probably fail (c) If your system is really so badly messed up, just reinstall it. Just fix the problems you actually see. – Faheem Mitha 16 hours ago
up vote 6 down vote accepted

Try this, remembering that I do not tested it and prepending sudo whn needed:

dpkg --get-selections > selections
dpkg --clear-selections
dpkg --set-selections < selections
apt-get --reinstall dselect-upgrade


share|improve this answer
My problem was completely different : I was not booting the correct kernel (!). I will accept your answer as it seems to do what I wanted (but untested also). – alex_reader Jun 12 '13 at 17:44
This won't work, and will completely break the system. Line 3 will uninstall apt, so it won't be possible to reinstall everything, afterwards. – rkjnsn Nov 4 '13 at 17:41
@rkjnsn: I updated the answer, check if it works. – Marco Sulla Nov 6 '13 at 9:17
Trying to do this nothing is being reinstalled, although the selections file is populated: pi@prodpi ~ $ sudo apt-get --reinstall dselect-upgrade Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. any idea? – andig Jun 9 '14 at 8:42
One reason I think your code won't work is because the command dpkg --get-selections list also deinstall packages. – Ortomala Lokni Feb 5 '15 at 23:20

In one of the ressouce cited by Lucas Malor, I found a script called populator which seem to be near the solution. If you set the packages selection variable to the list of all your packages

PKGLIST=$(dpkg --get-selections | grep -v deinstall| cut -f1)

you can then run the script and reinstall all packages but the system will probablaby have some problems. It would be better to test it in a virtual machine.

Here is a variant of the script from the link above:

# Script to pre-populate apt-get proxy for faster later downloads.
# It uses apt-get and wget to pull all the specified packages.

# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
   echo "You're not root, are you?" 1>&2
   exit 1

# Specify wanted packages

# Clears out the local repository of retrieved package files
apt-get clean

# Resynchronize the package index files from their sources
apt-get update

# Re-install specified packages at the newest version. 
apt-get install --reinstall $PKGLIST
share|improve this answer

When using RPM, in the event you cause a corruption in the package database, there is an option to rebuild this database, thus preventing you from having to go through basically a reinstall. As one user here pointed out this is done in Debian by dpkg --configure -a.

share|improve this answer
The role of dpkg --configure -a is to configure all unpacked and unconfigured packages. See man pages of dpkg and dpkg-reconfigureand also debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html – Ortomala Lokni Feb 5 '15 at 22:42

Just in case, try to reinstall each package:

for i in $(cat list.log); do apt-get install --reinstall "$i"; done

You may wish to add answer yes to all questions option too.

share|improve this answer

Try this instead since it will take your output and make it one giant line with spaces separating the filenames.

dpkg --get-selections | grep -v deinstall | awk '{print $1}' > list.log awk '$1=$1' ORS=' ' list.log > newlist.log apt-get install --reinstall $(cat newlist.log)

The only change to your original post is adding in the second awk statement, which could probably be done inline with the first to create the file you want.

This change will force apt-get to correctly redownload the packages and any missing dependencies that were not installed the first time and reinstall them in order.

If we do make it inline, I believe that it would look like this then:

dpkg --get-selections | grep -v deinstall | awk '{print $1}' | awk '$1=$1' ORS=' ' > list.log

And then make sure you really make the system has correct packages (or latest), clean the apt cache, update it and then re-download all the files (you can skip the first two steps if you only want what you have in the cache reinstalled):

apt-get clean && apt-get update && apt-get install --reinstall $(cat list.log)

I had over 2k packages installed on a system I upgraded that had a hangup. Using dpkg --configure -a finished the installation (it was in the final phase). I then ran this to make everything reinstall correctly.

Or as stated over at http://superuser.com/questions/298912/reinstall-debian-while-keeping-installed-packages-and-data:

sudo apt-get install --reinstall $(dpkg --get-selections | grep -w 'install$' | cut -f1)

Just make sure you run an "init 2" first before any reinstall, since some of the components of X or your favorite window manager may not like being reinstalled.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.