Installing packages on a machine to match another one

Sometimes you want to set up a new server and have the same packages installed on it as are installed on an existing one.

There are several tedious ways of doing this, and also a few pretty simple ones. Here are two of the simple ones.

Firstly

Get a list of the packages which are installed on the existing machine.

If the machine is running:

dpkg --get-selections >packages.txt

If the machine is not running but you have a backup:

dpkg --admindir=/pathtobackup/var/lib/dpkg --get-selections >packages.txt

Either way...

This will create a file called packages.txt containing a list of all the packages which have been installed or uninstalled on your machine, in a format suitable for transferring to another machine in order to make it match.

If you do not want the list to uninstall packages, you can filter the output simply:

dpkg --get-selections | grep "\sinstall$" >packages.txt

The file will now contain only the list of packages which have been installed (and will therefore not uninstall anything from the new machine).

Secondly

Transfer the list to the new machine and tell it to install the same things.

Copy the text file you created above by whatever means is most convenient, and then use:

/usr/lib/dpkg/methods/apt/update /var/lib/dpkg/
dpkg --set-selections <packages.txt
apt-get dselect-upgrade

Alternatively

There's a tool named apt-clone which will apparently do the above for you (disclaimer: I have not tried it).

On both machines you install the apt-clone package (which is a standard Debian/Devuan package) and then on the origin machine you do:

apt-clone clone source

(you can put anything you like in place of source), which will create a file named source.apt-clone-tar-gz.

Copy this file to the destination machine and use

apt-clone restore source.apt-clone.tar.gz

(putting whatever you used previously in place of source).


Go up
Return to main index.