Install (almost) the same list of Debian packages on multiple machines

  Last modified on Sunday 16 July 2017

PROJECT: The Lifecycle of Debian Objects .: Scenario: I have a whole bunch of packages installed on Machine A and I want to replicate that package selection on Machine B.

Let's go!

Machine A serves as the original source of the list of packages.

0. Make

Generate the list ...

$ dpkg --get-selections > pkg-list

The pkg-list file now contains the list of installed Debian packages on Machine A. However I want to make a few changes (hence the "almost" in the title) to the list.

Delete entries for packages that have been installed then removed (marked as deinstall) ...

$ sed -i '/deinstall/d' pkg-list

I also delete entries for packages that I built myself (identified using apt-show-versions) and are not available in the Debian package archives ...

ARRAY=( $(apt-show-versions | grep -v "stretch" | awk -F: '{print $1}') )
for package in "${ARRAY[@]}"
do
    sed -i "/$package/d" pkg-list
done

I made the generatePkgList shell script to create modified package lists.

1. Install

Copy pkg-list to Machine B and update its dpkg database of known packages ...

# avail=`mktemp`
# apt-cache dumpavail > "$avail"
# dpkg --merge-avail "$avail"
# rm -f "$avail"

Update the dpkg selections ...

# dpkg --set-selections < pkg-list

Use apt-get to install the selected packages ...

# apt-get dselect-upgrade

Link: Debian Administrator's Handbook - 6.2. aptitude, apt-get, and apt Commands

Happy hacking!

More • debianlinuxshellprogramming