Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

Try this command to change package status -

sudo 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-

sudo echo "zip install" | sudo dpkg --set-selections 

To change more packages at once use this command

dpkg --get-selections | grep <current-status> | sed s/<current-status>/<status>/ | sudo dpkg --set-selections

for example, to change all packages with status deinstall to install use -

dpkg --get-selections | grep deinstall | sed s/deinstall/install/ | sudo dpkg --set-selections
share|improve this answer
    
+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 Shah Jul 21 '12 at 7:21
1  
Wow, that works like a magic. I liked the design of theory and example approach. Congrats ! my friend. I hope you will give some more time to this site. –  Anwar Shah Jul 21 '12 at 10:37
add comment

Below is a quick method to clean 'deinstall' marks in dpkg selections.

First change marks from 'deinstall' to 'purge':

dpkg --get-selections |grep deinstall |sed s/deinstall/purge/ |dpkg --set-selections

Then:

dselect install
share|improve this answer
add comment

Graphical method

  • First open a terminal and run this command to get all the packages list with entries deinstall.

    dpkg --get-selections | grep deinstall > selections
    

    this will create a file named selections in the current directory with all deinstall entries.

  • Now open the file with gedit text editor. From command line, it is gedit selections

    enter image description here

  • Now Press CTRL+H to bring the replace window.

  • Type \tdeinstall in the search for field and write \tinstall in the replace field.

    enter image description here

  • Then Press Replace all button to change all entries. Save and close the file.

  • Now again in the terminal, type the command to change the dpkg database entries

    sudo dpkg --set-selections < selections
    

    Make sure, you are in the same directory as the selections file.

That's it. Job done. You can run dpkg --get-selections command to see the changes

share|improve this answer
add comment

Your Answer

 
discard

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.