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?

2 Answers 2


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
  • +1 for your answer. Though your answer is helpful, it will be more helpful, if you can provide a method to change all the packages. I'll try to use this method to generate a script.
    – Anwar
    Jul 21, 2012 at 7:21
  • It is dangerous to grep or sed for current status, because the package name could contain such string, too.
    – jarno
    Jan 11, 2016 at 0:15
  • 2
    @jarno Adding a dollar sign to the end of the regular expression in grep and sed makes it safe, because then it matches only at the end of the line.
    – Fritz
    Mar 14, 2016 at 18:48
  • 1
    @Fritz not quite safe; also beginning of word should be checked. Otherwise by install$ you find deinstall$, too.
    – jarno
    Mar 14, 2016 at 21:47
  • @jarno True that.
    – Fritz
    Mar 15, 2016 at 15:32

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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