From the MacPorts wiki (migration):
https://trac.macports.org/wiki/Migration
After saving the list of installed ports using:
port -qv installed > myports.txt
and deleting them with:
sudo port -f uninstall installed
Download and run the restore_ports script command. (If you installed MacPorts from the source code and used a custom prefix, you need to use the -p option when running restore_ports.tcl , see ./restore_ports.tcl -h .)
curl -O https://svn.macports.org/repository/macports/contrib/restore_ports/restore_ports.tcl chmod +x restore_ports.tcl sudo ./restore_ports.tcl myports.txt
source share