Generate a list of installed Debian packages on one device (and install on another)

Last updated on 2022-01-30 Tagged under  #debian   #linux 

When setting up a new device with Debian, it can be useful to have an updated list of all Debian packages installed on the current device, and replicate that configuration on the new device.

This is how I do it.

1. Generate a list of *.deb packages installed on current device, and save to $LIST ...

$ LIST="${HOME}/.pkg_list_deb-${HOSTNAME}"
$ dpkg-query -f '${binary:Package}\n' -W > $LIST

I put these commands in a script: pkg_list_deb

2. Keep $LIST updated. I add an alias to my ~/.bashrc that combines in a single command:

alias aaa="sudo apt update && apt list --upgradable && sudo apt full-upgrade && sudo apt-get autoclean && sudo apt autoremove && pkg_list_deb"

Reload the new settings, and run ...

$ source ~/.bashrc
$ aaa

3. Replicate the list on another device. Copy $LIST from current device to the new device. Install $LIST contents ...

$ sudo xargs -a $LIST apt install

Note: Confirm the new device lists the same repositories in /etc/apt/sources.list as the current device. Otherwise, some packages in $LIST might not be available.

Sources: pkg_list_deb and .bashrc

Thanks for reading! Read other posts?

» Later: Getting started with Neovim

« Earlier: Manage screen layout for laptop connected to external display