2

I have put together a debian instance with apt as the package manager that has many packages installed. I would like to install these same packages on another system that does not have an internet connection. Is there an easy way to generate a list of the packages I have installed ordered by dependencies, get the .deb of the packages so I can install on another computer?

My goal would also be to be able to update the other computer by regenerating the package list and .deb files and using this to do the update.

  • 1
    You don't need to have the packages ordered by dependency if you install them all at the same time. dpkg -l | awk '/^ii/ { print $2 ;}' should get you a list of fully installed packages. – icarus Jul 12 '19 at 02:32

1 Answers1

5
  1. To get the installed packages list:

     dpkg --get-selections '*' > /tmp/selections.txt
    
  2. To re-download the installed packages on the machine with internet access:

    apt-get clean
    awk '$2=="hold" || $2 == "install" {print $1}' /tmp/selections.txt | 
      xargs -r apt-get -d -y reinstall
    

This will will download all the installed packages into /var/cache/apt/archives/. xargs is used here in case the list of installed packages is too large to fit on one command line.

Note: running apt-get clean is optional. It will delete all .deb files that were already in /var/cache/apt/archives. This is done only to minimise the number of packages that will need to be copied to the non-internet machine (e.g. old versions, uninstalled packages, etc that are still present in that directory). The downside is that all installed packages will be downloaded again, even if they were already in the archives directory.

  1. Copy /tmp/selections.txt to /tmp/ on the non-internet machine.

  2. Copy everything in /var/cache/apt/archives to the same directory on the non-internet machine. The method doesn't matter - scp, rsync, USB stick, external hard-drive, whatever. The important thing is that they are copied to /var/cache/apt/archives on the target machine.

  3. on the target (non-internet) machine run:

    dpkg --set-selections < /tmp/selections.txt
    apt-get dist-upgrade
    

If you want the apt-get dist-upgrade to uninstall packages that were previously installed on the target machine but NOT installed on the other machine, then run dpkg --clear-selections before running dpkg --set-selections.

See the dpkg man page for more details about the --get-selections, --set-selections, and --clear-selections options.

cas
  • 78,579
  • Alternatively, see https://unix.stackexchange.com/a/208163/7696 - that uses apt-clone to do this automatically. I'm too used to doing things manually, the "old-fashioned" way before new-fangled tools like apt-clone existed. – cas Jul 12 '19 at 03:03
  • See also https://unix.stackexchange.com/questions/191662/how-do-i-replicate-installed-package-selections-from-one-debian-system-to-anothe – cas Jul 12 '19 at 03:07