# MacPorts Cheat Sheet #### Cheat sheet at its fullest within [Dash](https://kapeli.com/dash), the macOS documentation browser. [MacPorts Guide](https://guide.macports.org/). ## Information **Search directory for ports** ``` port search [--name] [--regex] '' ``` Get information about a port ``` port info ``` **List installed ports** For just a list of the ports you have explicitly installed: ``` port echo requested ``` For a list of everything installed by MacPorts, including all dependencies: ``` port installed ``` ## Install/Uninstall Ports **Install a port** ``` [sudo] install ``` **If an install fails** If a port install fails for some reason, clean up the attempt before trying again. ``` [sudo] port clean ``` If you believe the downloaded files are corrupt, you can also delete any files downloaded for that port: ``` [sudo] port clean --dist ``` **Uninstall a port** Note: This does not uninstall dependencies that were installed with this port. To remove unused dependencies, see the Maintenance section. ``` [sudo] uninstall ``` ## Updates **Update MacPorts and directory of available ports** It's recommended you do this every time you start using MacPorts on any given day. ``` [sudo] port selfupdate ``` **List ports that have available updates** ``` port outdated ``` **Update all ports** ``` [sudo] port upgrade outdated ``` **Update a specific port** ``` [sudo] port upgrade ``` ## Cleanup/Maintenance **List inactive ports** By default, upgrading ports in MacPorts does not remove the older versions. This is a safety measure to ensure you can go back to a working and tested version in case an update goes wrong. Use ``` port installed inactive ``` **Uninstall all inactive ports** To save disk space, you should periodically uninstall any old versions you no longer need. ``` [sudo] port uninstall inactive ``` **List no-longer needed dependencies (leaves)** After a while of using MacPorts, installing and uninstalling ports, packages that have been automatically installed as dependencies for other ports are left behind, even though they are no longer necessary. Ports that have not been manually installed (“requested”) and do not have any dependents are called “leaves” and can be identified using the leaves pseudo-port. To list leaves ``` port echo leaves ``` **Uninstall no-longer needed dependencies (leaves)** ``` [sudo] port uninstall leaves ``` *Note that the uninstallation can cause new ports to become leaves. To uninstall all leaves, you would have to repeat the process until port echo leaves comes back empty.* To automate this, you can use `--follow-dependencies` when uninstalling. ``` [sudo] port uninstall --follow-dependencies leaves ``` To go through this process interactively so you can make sure you're not uninstalling anything you want to keep, you can install the port_cutleaves port. After installation, run it with ``` [sudo] port_cutleaves ``` ## Uninstall MacPorts **Uninstall all Ports** ```sh sudo port -fp uninstall installed ``` **Uninstall Users and Groups** ```sh sudo dscl . -delete /Users/macports sudo dscl . -delete /Groups/macports ``` **Uninstall everything else** 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](https://guide.macports.org/chunked/installing.macports.uninstalling.html#installing.macports.uninstalling.users) first. ```sh 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 ```