Generate a list of installed packages and use it to reinstall packages

We create a text file with all the names of the packages you have.

dpkg --get-selections | grep install$ > llista_paquets

Dpkg command options:

Set package selections using file read from stdin. This file should be in the format ‘ ‘, where state is one of install, hold, deinstall or purge. Blank lines and comment lines begin-
ning with ‘#’ are also permitted.

apt-get update
apt-get dist-upgrade
apt-get upgrade
dpkg --set-selections < llista_paquets

Apt-get command options:

dselect-upgrade is used in conjunction with the traditional Debian packaging front-end, dselect(8). dselect-upgrade follows the changes made by dselect(8) to the Status field of available packages, and performs the actions necessary to realize that state (for instance, the removal of old and the installation of new packages).
I shall use the system we want to install to install it:

apt-get dselect-upgrade