sudo apt-get install apt-clone
apt-clone clone foo
Copy foo.apt-clone.tar.gz to the new machine and run
sudo apt-get install apt-clone
sudo apt-clone restore foo.apt-clone.tar.gz
apt-clone may work between related distributions,
e.g. Debian and Ubuntu. Use restore-new-distro instead of restore in that case.
If that fails, use the manual method with dpkg --get-selections and apt-mark,
and fiddle with the package list until apt is satisfied.