Uninstalling MacPorts is a drastic step and, depending on the issue you are experiencing, you may not need to do so. If you are unsure, ask on the macports-users mailing list first. If you are sure you want to uninstall, read on.
If you want to uninstall MacPorts and the +port+
command is functioning, first uninstall all the installed ports by running this command in the Terminal:
$ sudo port -fp uninstall installed
All that will be left in your installation prefix now will be files that were not registered to any port.
This includes configuration files, databases, any files which MacPorts renamed in order to allow a forced installation or upgrade, and the base MacPorts software itself.
You may wish to save your configuration files (most are in $prefix/etc
), databases, or any other unique data by moving it aside.
If the +port+
command is not functioning, you can proceed on to the next steps, but if you had installed any ports that install files to nonstandard locations, those files might not be removed.
When MacPorts is installed, a macports
macOS user and group are created for privilege separation.
If you want to remove them, you can use these commands from an account that has admin privileges:
$ dscl -p . -delete /Users/macports $ dscl -p . -delete /Groups/macports
If you configured MacPorts to use a different user or group name, then specify that instead of macports
.
Individual ports may create users and groups as well; you can remove them with the same commands, but replacing macports
with the user or group name you wish to delete.
If you want to remove all remaining traces of MacPorts, run the following command in the Terminal.
If you have changed +prefix+
, applications_dir
or frameworks_dir
from their default values, then replace /opt/local
with your +prefix+
, replace /Applications/MacPorts
with your +applications_dir+
, and/or add your frameworks_dir
to the list, respectively.
If you are running macOS 10.15 Catalina or later and have not disabled System Integrity Protection (SIP), you will need to remove the macports
user first.
$ sudo rm -rf \ /opt/local \ /Applications/DarwinPorts \ /Applications/MacPorts \ /Library/LaunchDaemons/org.macports.* \ /Library/Receipts/DarwinPorts*.pkg \ /Library/Receipts/MacPorts*.pkg \ /Library/StartupItems/DarwinPortsStartup \ /Library/Tcl/darwinports1.0 \ /Library/Tcl/macports1.0 \ ~/.macports
If you use a shell other than bash (perhaps tcsh), you may need to adjust the above to fit your shell’s syntax.
Depending on which version of MacPorts you have and which ports you have installed, not all of the above paths will exist on your system; this is OK.