Whenever I install a program via MacPorts, it gets and installs lots of dependencies. When I uninstall said program, how do I make MacPorts recursively remove all unused dependencies with it?
Mac – How to remove unused MacPorts packages
macports
Related Question
- Mac – Repairing macports after deleting image folders
- MacOS – MacPorts on mountain lion – cannot install apache2 due to gettext package
- Mac – Problem with MacPorts
- Mac – Why does installing Caffe via Macports install unrelated ports
- Mac – How fix broken Macports installation after manual deletion of app
- Mac – Homebrew asked me to move macports now it does not work
- Terminal – How MacPorts Works with /Applications/MacPorts and /opt/usr/local/bin
Best Answer
To avoid accidentally cutting leaves that might be things you requested you should install the
port_cutleaves
package then runsudo port_cutleaves
https://guide.macports.org/#using.common-tasks.keepleanMacPorts 1.9.0 added the
sqlite
portdbformat
and MacPorts 2.0.0 dropped the oldflat
format. Thesqlite
port DB format is the default for new installations; old installations that were upgraded to 1.9.x will continue to use theflat
format1. You can convert a 1.9.xflat
system to thesqlite
format by upgrading to MacPorts 2.0 or by changing theportdbformat
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 withsudo 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.
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:
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):
There are several sections in the MacPorts Guide that also describe the process of using
leaves
to uninstall unneeded ports.