Ubuntu – Backup and Restore list of installed packages and APT sources

aptdpkgpackage-managementsoftware installationUbuntu

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.

Best Answer

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
Related Question