With debian (and derivatives like ubuntu, mint, etc) you can save the current set of selected packages with:
dpkg --get-selections '*' > /tmp/selections.txt
Copy that file to a USB stick or somwehere convenient, so you can use it with
dpkg --set-selections after you have re-formatted and installed the base OS.
Login as root (or
sudo -i to get a root shell) and:
- mount the usb stick, e.g. under /media
dpkg --set-selections < /media/myusbstick/selections.txt
Note: this will NOT keep any custom configuration of any packages. If you want to do that, you will need to backup your old
/etc directory and restore (some or all of) that after the packages have been re-installed on the new system. I doubt that this is an issue, because the only good reason to do what you want (fresh install, re-install all the same packages) is if you have completely messed up the configuration of something important. Even then, you're probably better off purging that package (or packages) and then re-installing it/them.
--set-selections method can be useful for small-scale cloning of mostly-similar machines, without the need to set up pxe, tftp, etc infrastructure, or clonezilla and an nfs or samba server. For large-scale cloning, it's worth putting in the effort to set up the infrastructure to automate mass-cloning.