Skip to content

MacPorts keeps build sources and inactive versions until you clean them

The ports tree, distfiles and inactive ports all accumulate. The two commands that reclaim most of it safely.

4 min read

MacPorts builds from source, which means it downloads distribution files, extracts them, compiles in a work directory, and keeps the results. Unlike a binary package manager, most of that intermediate material stays until you clean it explicitly.

Measure it

du -sh /opt/local 2>/dev/null
du -sh /opt/local/var/macports/{distfiles,build,software} 2>/dev/null | sort -h
port installed | wc -l
port echo inactive

The two commands that matter

sudo port clean --all installed     # work directories and distfiles
sudo port uninstall inactive        # superseded versions

The first removes build directories and downloaded source archives for everything installed, which is often the majority of the space. The second removes older versions of ports that have been upgraded, which MacPorts keeps deliberately so you can revert.

What each part is

DirectoryHoldsSafe to clean
distfilesDownloaded source archivesYes, redownloaded if rebuilt
buildCompilation work directoriesYes, always
softwareInstalled port archivesOnly inactive versions
sourcesThe ports tree itselfKeep, it is how ports are found

Ports you no longer use

Dependencies installed for something you have since removed stay installed, in the same way Homebrew leaves dependencies behind. Listing what is requested rather than pulled in shows the difference:

port echo requested
sudo port uninstall --follow-dependencies <portname>

If you use both package managers

A Mac running MacPorts and Homebrew has two complete parallel installations of many of the same libraries, in /opt/local and /opt/homebrew. That is workable and it is worth knowing about, because measuring only one of them understates the total by half.

Common questions

How do I free space used by MacPorts?

Run sudo port clean --all installed to remove build directories and downloaded sources, then sudo port uninstall inactive to remove superseded versions of upgraded ports.

What are distfiles in MacPorts?

Downloaded source archives kept after building. They are only needed if you rebuild the same version, so cleaning them is safe and usually reclaims a substantial amount.

What does port uninstall inactive do?

It removes older versions of ports that remain installed but inactive after an upgrade. MacPorts keeps them so you can revert, and they accumulate with every upgrade.

Where does MacPorts install everything?

Under /opt/local, separate from Homebrew's /opt/homebrew. A Mac with both has two parallel sets of libraries, so measuring only one understates the total.

Read next