Reinstalling all Debian packages

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

sudo aptitude reinstall '~i'

which will reinstall all currently installed packages.

Method 2

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 --reinstall dselect-upgrade

Sources:

Method 3

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.

Method 4

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:

#!/bin/bash
#
# 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
fi

# Specify wanted packages
PKGLIST="exaile" 

# 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

Method 5

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.

Method 6

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.

Method 7

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.

Method 8

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x