First, let’s see how much macports use up on my system:
$ du -sh /opt 8.1G
Next, how many packages do I have installed in total:
sudo port installed | wc
538
And how many packages are active:
sudo port installed | grep active | wc
253
Now let’s trim the entire collection, by uninstalling all inactive packages:
sudo port uninstall inactive
If you have some dependency issues, add ‘-f’ flag to the port command that will ignore dependencies.
This reduced the disk usage in /opt to 4.8G, and got the number of all installed ports to 254.
More cleanup:
sudo port clean --all installed
This removes all temporary files generated while building and installing packages. After that, I got down to 3.6G in /opt. Not bad down from 8.1G.