The approach is simple: generate a list of installed packages on Debian-based systems and install this list of packages on the new box. This approach is useful when you want to install the same packages on another fresh OS install for example.
1. To export the list of installed packages, proceed as follows:
dpkg --get-selections | grep -v deinstall > LIST_FILE
The file LIST_FILE is small so it can be emailed to yourself by using:
dpkg --get-selections | grep -v deinstall > LIST_FILE && cat LIST_FILE | mailx -s "`hostname -f`: Package list" "email@example.com"
2. Once you’ve got your server up and running with a fresh base install
apt-get update apt-get dist-upgrade
3. Move your LIST_FILE file into your home directory and run the following commands to recover the previous generated list:
dpkg --clear-selections dpkg --set-selections < LIST_FILE
4. Install the packages