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.

  • 1
    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. Commented Jun 12, 2013 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. Commented Jun 12, 2013 at 13:01
  • 2
    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. Commented Feb 9, 2016 at 7:59

8 Answers 8


When using Aptitude there is an easy and fast way to do it:

sudo aptitude reinstall '~i'

which will reinstall all currently installed packages.

  • 4
    Bonus question: how do I get this to skip packages which cannot be re-fetched, rather than refusing to do anything if a single package is no longer available?
    – user149408
    Commented Jul 3, 2022 at 22:00
  • 2
    @user149408 - I couldn't find a way to do it automatically, but if the aptitude command above fails with a bunch of "Can't find a source to download version..." then you can just append that package name to the command, negated. For instance, if aptitude can't find plocate, you can run this: aptitude reinstall '~i !plocate'. Commented Nov 2, 2022 at 21:01
  • 4
    This also works with apt on recent Debian releases. Commented May 16, 2023 at 9:10
  • 1
    If you want to keep current configuration files without being prompted: sudo apt reinstall -o Dpkg::Options::="--force-confold" '~i' Commented Dec 30, 2023 at 3:37

Try this, remembering that I did not test it:

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


  • 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). Commented Jun 12, 2013 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
    Commented Nov 4, 2013 at 17:41
  • 3
    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
    Commented Jun 9, 2014 at 8:42
  • 1
    Yeah, this didn't do anything on my system either. Same result as @andig reports in the comment above.
    – mlissner
    Commented Mar 6, 2015 at 6:44
  • 1
    @FaheemMitha: I'm not encouraging nothing and I clearly stated that it's also untested. I encourage you to explain your doubts more clearly. Commented Feb 9, 2016 at 9:39

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.

  • That will call apt-get for each line in the list though, which is unproductive. That would cause a lot of code, such as regenerating man pages, to execute more than once. Instead you would want all packages to be listed inside a single apt-get call. Depending on a number of packages, that may save a huge amount of time.
    – Hi-Angel
    Commented Dec 12, 2022 at 15:40

In one of the resources cited by Lucas Malor I found a script called populator which seems 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 probably have some problems. It would be better to test it in a virtual machine first.

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

If error is shown that specific packages can't be reinstalled run this command to try again:

sudo apt-get -y autoremove

I had some strange behavior, so I reinstalled all packages like this. Fixed the problem for me. Takes couple of hours.

for package in $(apt list --installed | grep -P ".*(?=/)" -o); do echo $package; done;

replace echo with sudo apt install --reinstall -y
to reinstall all packages, or with anything else if needed.


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 https://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.

  • Unless you've modified IFS, unquoted $(cat file) tokenizes on any whitespace and gives exactly the same result whether the file is delimited by newlines or spaces. --reinstall might help but was already given twice before this. Commented Oct 9, 2017 at 4:20

Doing this via apt is pretty simple:

apt list --installed | cut --delimiter=/ --fields=1 | xargs apt reinstall -y

The apt list --installed part does just what one would guess. The | character pipes the standard output of the apt command to the standard input of the cut command. The cut --delimiter=/ part tells the cut command to use / as the delimiter, and --fields=1 tells cut to use the first field, that is, the text before the first / that appears in the output of the apt list --installed command. In this case, the result of the cut command is a list of all installed packages without all the additional information we don't need from the apt list --installed command.

The next | pipes the standard output of the cut command, the list of all installed packages, to the standard input of the xargs command, which, in turn, invokes apt reinstall -y for each one of the packages that are currently installed.

Note: depending upon your apt configuration, the apt reinstall -y part may install updates to your existing packages instead of the exact versions you currently have installed.

  • Really don't know what's wrong, but your command line results in pkg list starting with the word "Listing...". So the whole command gives off error : "Unable to find packages Listing...". Other than that, it works fine, thank you. Commented Mar 27, 2022 at 21:21
  • This is very close: apt list --installed | tail -n +1 | cut --delimiter=/ --fields=1 | xargs apt reinstall -y The tail -n +1 skips the first line of output from apt which contains "Listing..." Commented Mar 7, 2023 at 19:38

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.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .