MacPorts, formerly DarwinPorts, is a package manager for macOS and Darwin. It is an open-source software project that aims to simplify the installation of other open source software. It is similar in function to Fink and the BSD ports collections.
MacPorts allows the installation of a number of packages by entering the command sudo port install packagename in the Terminal, which will then download, compile if necessary, and install the requested software, while also installing any required dependencies automatically. Installed packages can be updated with the command sudo port upgrade outdated. MacPorts supports universal binaries for PowerPC, Intel-based, and Apple silicon versions of macOS, but migrating from a PowerPC installation of MacPorts to a version on an Intel Mac requires reinstalling all installed ports.
There are three main usage modes of port that assist in updating installed software:
sync updates the local ports tree. It does not upgrade any installed packages, but instead retrieves information about new and updated software. It is similar in function to brew update or apt update.
selfupdate has the same functionality as sync but also updates the MacPorts system. In most cases, this should be used in preference to just running sync by itself, and it is recommended to run this each time before using MacPorts.
upgrade upgrades any installed ports and its dependencies to the latest version found in the local ports tree. It is similar in function to apt upgrade.
As an example, one common task is to update outdated ports. This can be done by running the following:
sudo port selfupdate
sudo port upgrade outdated
MacPorts supports logical operators such as and, or and not, as well as glob patterns (enabled by default) and regex (enabled via --regex). For instance, to update outdated ports excluding all PHP versions, change the above command to the following:
sudo port selfupdate
sudo port upgrade outdated and not php*
Users can indicate one or more packages that they wish to install via the install mode, and MacPorts will aim to install them and its dependencies.