MacPorts is a package manager for Mac operating system. It is an easy to use system for compiling, installing, and managing open source software.
A package is a collection of files that are bundled together and can be installed and removed as a group.
Conceptually Macports is divided into two parts:
- MacPorts Base: The software that we will install (the package manager)
- Set of available ports: A port is a set of specifications contained in a Portfile that defines an application, its characteristics, and any files or special instructions required to install it.
This allows you to use a single command to tell MacPorts to automatically download, compile, and install applications and libraries (Ref: doc)
- You need to install Apple’s Developer Tools
Open spotlight by typing ⌘ command+space and then type “terminal” in the spotlight and launch the terminal. Run the command below and install Apple’s Command Line Developer Tools:
- Few ports require xcode installation but for now you can skip this step. You can install it if MacPorts tells you to do so.
You can install MacPorts using any of the following:
- Install a binary package (recommended)
- Install it from source
- Git install
We will use binary package to install it. It is easy and sets all the shell environment variables need to run port.
- Download the latest version of MacPorts from it’s official page
- Double click the downloaded installer (.pkg file)
- Once installation is finished, launch the terminal and run
You can run below command to check if the shell environment variables are set
You should see below line at the beginning of the path
Let’s Install a port (a package) using MacPorts. If you want to install a version of python or MySQL then first you have to check if that version is available. We can
search action with
--regex switch to search all the available versions of python
port search --name --line --regex '^python\d*$'
This will return an output like this
python26 2.6.9 lang An interpreted, object-oriented programming language
python27 2.7.18 lang An interpreted, object-oriented programming language
python32 3.2.6 lang An interpreted, object-oriented programming language
python33 3.3.7 lang An interpreted, object-oriented programming language
python34 3.4.10 lang An interpreted, object-oriented programming language
python35 3.5.10 lang An interpreted, object-oriented programming language
python36 3.6.15 lang An interpreted, object-oriented programming language
python37 3.7.17 lang An interpreted, object-oriented programming language
python38 3.8.18 lang An interpreted, object-oriented programming language
python39 3.9.18 lang An interpreted, object-oriented programming language
python310 3.10.13 lang An interpreted, object-oriented programming language
python311 3.11.7 lang An interpreted, object-oriented programming language
python312 3.12.1 lang An interpreted, object-oriented programming language
To install python311, run
sudo port instal python311
To check the installation, launch the terminal again and type
and you will get
MacPorts install it’s binary in
/opt/local/bin. To verify if you are using the python installed by MacPorts, run
which python3.11 # Verify if you are using the port installed by MacPorts
It will return
To make it default python (you can use just
python3 instead of
sudo port select --set python3 python311
You can also install multiple ports together. For example, below command will install php 8.1, MySQL 8.1 and apache 2
sudo port install php81 mysql81 apache2
man port: Man page for
port help: Get a brief info about an action. e.g.
port help installwill return some info about
port install: Install a port. e.g.
port install python39
sudo port selfupdate: Update local (installed) ports.
port list: Lists the most recent version available in MacPorts or display a list of all available ports if no ports are specified. For e.g.
port list python39will list the current available version of
port installed: List all installed ports.
port outdated: List outdated local ports.
sudo port upgrade: Upgrade local outdated ports.
port info: Get info about a port. e.g.
port info python39.
port deps: List dependencies of a port. e.g.
port deps python39.
sudo port clean: Clean indeterminate files of failed installation.
sudo port uninstall: Uninstall a port. e.g.
sudo port uninstall python39.
If you try to install a port and for some reason installation fails then you should run
sudo port clean portnamebefore reinstalling it.
If you are upgrading your macOS (major version upgrade), then you need to migrate all ports to the new macOS version. Follow all the steps mentioned on official site: Migrating MacPorts after a major operating system upgrade or from one computer to another.