Apple - How to remove unused MacPorts packages?
To avoid accidentally cutting leaves that might be things you requested you should install the port_cutleaves
package then run sudo port_cutleaves
https://guide.macports.org/#using.common-tasks.keeplean
MacPorts 1.9.0 added the sqlite
portdbformat
and MacPorts 2.0.0 dropped the old flat
format. The sqlite
port DB format is the default for new installations; old installations that were upgraded to 1.9.x will continue to use the flat
format1. You can convert a 1.9.x flat
system to the sqlite
format by upgrading to MacPorts 2.0 or by changing the portdbformat
value in /opt/local/etc/macports/macports.conf
and then issuing a port command as root (e.g. sudo port installed
).
One of the features of the new format is that it keeps track of “requested” versus “unrequested” port installations. An unrequested port is one that was only installed because some other port depends on it. The leaves
pseudo-portname expands to all the unrequested ports upon which no other installed port depends. You can use this to “clean up” unneeded ports even if you did not originally uninstall them with sudo port uninstall --follow-dependencies portname
(which will do what you want, but only if you remember to use it every time you uninstall something).
You should examine your existing leaves before uninstalling any of them.
port echo leaves
Some common leaves (automake
, gperf
, libtool
, pkgconfig
) are build-time dependencies of common ports, so you may want to “request” them (sudo port setrequested port1 port2 port3 …
) to avoid uninstalling them just to have to reinstall them later.
You can uninstall any remaining leaves quite easily:
sudo port uninstall leaves
Note: Before pruning your leaves, you may also want to uninstall old versions of ports that are no longer “active”. This may reveal a few more leaves (i.e. ports that are dependencies of ports that are installed, but inactive):
sudo port uninstall inactive
There are several sections in the MacPorts Guide that also describe the process of using leaves
to uninstall unneeded ports.
From the docs:
The uninstall action will uninstall an installed port.
%% sudo port uninstall vile Note
To also recursively uninstall the ports that the given port depends on, use the
‑‑follow‑dependencies
flag. This will not uninstall dependencies that are marked as requested or that have other dependents.To recursively uninstall all ports that depend on the given port before uninstalling the port itself, use the
‑‑follow‑dependents flag
.If a port is a dependency of another installed port, uninstall will not remove it unless you remove the dependent port(s) first. To override this behavior, use the -f (force) switch. This will obviously break the dependents. Don't force uninstall ports unless you know what you are doing.
%% sudo port -f uninstall vile
Note the major caveat in the last paragraph. Dependencies are exactly that—dependencies—and different apps can (will) require the same dependencies.
The command to remove a port and its dependents is:
sudo port uninstall --follow-dependents foo
However, if the port you are uninstalling has dependents it will not uninstall without the -f
(force) flag.
Of course you should start by reading over the MacPorts Guide specifically looking into the Uninstall guide section.