How do you remove MacPorts and all the packages it has installed?

From the manual, uninstalling MacPorts works as follows. You need to first uninstall all ports:

sudo port -fp uninstall --follow-dependents installed

If port is not found, try /opt/local/bin/port instead.

Also, to remove remainders of MacPorts, you will need to delete the following files by this single command (copy and paste line-by-line to Terminal):

sudo rm -rf /opt/local 
sudo rm -rf /Applications/DarwinPorts 
sudo rm -rf /Applications/MacPorts 
sudo rm -rf /Library/LaunchDaemons/org.macports.* 
sudo rm -rf /Library/Receipts/DarwinPorts*.pkg 
sudo rm -rf /Library/Receipts/MacPorts*.pkg 
sudo rm -rf /Library/StartupItems/DarwinPortsStartup 
sudo rm -rf /Library/Tcl/darwinports1.0 
sudo rm -rf /Library/Tcl/macports1.0 
sudo rm -rf ~/.macports

Warning: Don't run a sudo command—especially a rm -rf one—unless you know what it's doing, and enter each line individually if you're unsure.

Note that MacPorts creates its own user and user group. They can be removed, too. See this answer over on Ask Different for more info.

Finally, each port installed through MacPorts may again create its own user and group, so you may have to perform a manual cleanup.


This guide helped me remove MacPorts: http://bitboxer.de/2010/06/03/moving-from-macports-to-homebrew/

Here's a summary (in case the link goes dead): First, uninstall MacPorts:

sudo port -f uninstall installed

Second step: remove everything that is left from MacPorts (check for MySQL and other stuff in /opt/local first):

sudo rm -rf /opt/local
sudo rm -rf /Applications/DarwinPorts
sudo rm -rf /Applications/MacPorts
sudo rm -rf /Library/LaunchDaemons/org.macports.*
sudo rm -rf /Library/Receipts/DarwinPorts*.pkg
sudo rm -rf /Library/Receipts/MacPorts*.pkg
sudo rm -rf /Library/StartupItems/DarwinPortsStartup
sudo rm -rf /Library/Tcl/darwinports1.0
sudo rm -rf /Library/Tcl/macports1.0
sudo rm -rf ~/.macports

After that you should remove the /opt/local/bin from your $PATH