How to set the package selection status to the current status?
I have made a dpkg --clear-selections
command and found that all my packages are selected for removal. As the man pages is saying
--clear-selections : Set the requested state of every non-essential package to deinstall.
and I later knew, If I do a sudo apt-get dselect-upgrade
all packages will be removed.
I checked this question in Ask Ubuntu, and read the meaning of each various flags in dpkg -l
command. There says, The first column shows "desired package state" or selection state and second column shows "current state".
Since, I have no dependency problem now, I want to set my selection state as the desired state in dpkg database. How can I do this?
I haven't given the output of dpkg -l
because of large output. The output is all ri
columns.
Also when I did the command sudo apt-get dselect-upgrade
, it gave me this message,
......... After a long list of package names to be removed... WARNING: The following essential packages will be removed. This should NOT be done unless you know exactly what you are doing! apt ubuntu-keyring (due to apt) libapt-pkg4.12 (due to apt) libstdc++6 (due to apt) gnupg (due to apt) base-files bash 4 upgraded, 0 newly installed, 1764 to remove and 1 not upgraded. Need to get 0 B/1,359 kB of archives. After this operation, 3,078 MB disk space will be freed. You are about to do something potentially harmful. To continue type in the phrase 'Yes, do as I say!' ?]
Is there any way to reset the packages selection state to the current installed state?
Try this command to change package status -
echo "<package-name> <status>" | sudo dpkg --set-selections
Say you have set status of package zip
to deinstall
. To rollback to original status install
run this command-
echo "zip install" | sudo dpkg --set-selections
To change more packages at once use this command
dpkg --get-selections | sed -n 's/\<<current-status>$/<status>/p' | sudo dpkg --set-selections
for example, to change all packages with status deinstall to install use -
dpkg --get-selections | sed -n 's/\<deinstall$/install/p' | sudo dpkg --set-selections
Ok I just needed to do this. Thanks @sarowar for the command. Steps to script doing this for all installed packages:
export IFS='
'
for i in $(dpkg -l |egrep '^[a-z]i.*' |awk '{print $2" install"}') ; do echo $i|dpkg --set-selections ; done
unset IFS