I commonly reinstall Ubuntu and back up my APT stuff [sources, keys and installed package lists] using the tutorial at https://askubuntu.com/a/99151/371765. However I commonly also remove software such as totem, transmission, unity scopes, etc.

When the install has finished and I restore my APT sources, keys, and installed packages from the previous install, I find I get the following:

  1. I get a warning saying dpkg: warning: package not in database at line ###: vlc [vlc is an example, it could be htop or iotop]. I think it does this warning for every package to restore in the universe repos, however I am not too sure.
  2. Anything uninstalled [totem, transmission, firefox, simple-scan, etc] on the previous system stays installed on the new system.

How can I make it so that anything uninstalled from the previous system gets uninstalled on the new system during installation of other packages [eg vlc]?

I have a made a start with diff plans, however when trying to convert version numbers to the word "test" [for testing purposes] in the Ubuntu 14.04.2 manifest, it converts all of the line and not a portion of it.

  • Please don't cross-post. Thanks for pointing it out but please delete the copies from AU and SU.
    – terdon
    Mar 18, 2015 at 13:28

2 Answers 2


A slight variation on Installing packages by importing the list with dpkg --set-selections should do the trick.

Save the list of packages on your reference system:

dpkg --get-selections > packages.lst

Then install packages based on that list on your target system, after updating the list of available packages:

dpkg --merge-avail <(apt-cache dumpavail)
dpkg --clear-selections
dpkg --set-selections < packages.lst
apt-get dselect-upgrade
  • I'll try that the next time I (re)install Ubuntu/Ubuntu distro
    – user100763
    Mar 19, 2015 at 2:38
  • When running sudo dpkg --merge-avail <(apt-cache dumpavail) [sudo needed for write access], this error comes up: Updating available packages info, using /dev/fd/63. dpkg: error: failed to open package info file /dev/fd/63 for reading: No such file or directory. Any ideas why? Freshly installed system. EDIT: The third command does what 1. says in the question, probably because the first command failed.
    – user100763
    Mar 21, 2015 at 6:20
  • 1
    You need to run the command substitution within the same shell as dpkg, so either become root beforehand, or run sudo bash -c "dpkg --merge-avail <(apt-cache dumpavail)". Mar 21, 2015 at 12:40
  • I was looking for a way to do a partial list. This is NOT it.
    – cmcginty
    May 11, 2018 at 6:19
  • @cmcginty are you user100763? May 11, 2018 at 6:38

Backup the packages installed

  1. get the list of installed packages
  2. remove those where deinstalled
  3. remove the installed column
  4. save the list
# dpkg --get-selections | grep -v deinstall | awk '{print S1}' > package.lst

Restore from package.lst

# aptitude install -y $(cat package.lst)

Your Answer

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