Backup and Restore list of installed packages and APT sources

14,500

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
Share:
14,500

Related videos on Youtube

Community
Author by

Community

Updated on September 18, 2022

Comments

  • Community
    Community over 1 year

    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.

    • terdon
      terdon about 9 years
      Please don't cross-post. Thanks for pointing it out but please delete the copies from AU and SU.
  • Admin
    Admin about 9 years
    I'll try that the next time I (re)install Ubuntu/Ubuntu distro
  • Admin
    Admin about 9 years
    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.
  • Stephen Kitt
    Stephen Kitt about 9 years
    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)".
  • cmcginty
    cmcginty almost 6 years
    I was looking for a way to do a partial list. This is NOT it.