If you are using macOS, you should install MacPorts using the macOS package installer unless you do not wish to install it to /opt/local/
, the default MacPorts location, or if you wish to install a pre-release version of MacPorts base.
However, if you wish to install multiple copies of MacPorts or install MacPorts on another OS platform, you must install MacPorts from the source code.
The macOS package installer automatically installs MacPorts, sets the shell environment, and runs a selfupdate operation to update the ports tree and MacPorts base with the latest release.
Download the latest MacPorts-2.6.2-….pkg
installer from the releases on GitHub. Here are direct links for the latest versions of macOS:
MacPorts-2.6.2-10.12-Sierra.pkg
+port+
in a new terminal window.$ port version
Version: 2.6.2
In case of problems such as “command not found”, make sure that you opened a new terminal window or consult Section 2.5, “MacPorts and the Shell”. Otherwise, please skip the remainder of this chapter and continue with Chapter 3, Using MacPorts in this guide.
If you installed MacPorts using the package installer, skip this section. To install MacPorts from the source code, follow the steps below.
Download and extract the MacPorts 2.6.2 tarball. Either do so using your browser and the Finder, or use the given commands in a terminal window.
$ curl -O https://distfiles.macports.org/MacPorts/MacPorts-2.6.2.tar.bz2 $ tar xf MacPorts-2.6.2.tar.bz2
Afterwards, perform the commands shown in the terminal window. If you wish to use a path other than /opt/local
, follow the instructions for installing multiple copies of MacPorts instead.
$ cd MacPorts-2.6.2/ $ ./configure $ make $ sudo make install
If you installed MacPorts using the package installer, skip this section.
There are times when some may want to run MacPorts from a version newer than the current stable release. Maybe there’s a new feature that you’d like to use, or it fixes an issue you’ve encountered, or you just like to be on the cutting edge. These steps explain how to setup MacPorts for developers, using only Git to keep MacPorts up to date.
Though a distinction is made between pre-release and release versions of MacPorts base, the ports collection supports no such distinction or versioning. The selfupdate command installs the latest ports tree, and updates MacPorts base to the latest released version.
Check out MacPorts source
Pick a location to store a working copy of the MacPorts code.
For this example, /opt/mports
will be used, but you can put the source anywhere.
This example will create /opt/mports/macports-base
containing everything needed for MacPorts.
$ mkdir -p /opt/mports $ cd /opt/mports $ git clone https://github.com/macports/macports-base.git $ git checkout v2.6.2 # skip this if you want to use the development version
Build and Install MacPorts
MacPorts uses autoconf and makefiles for installation.
These commands will build and install MacPorts to /opt/local
.
You can add --prefix
to ./configure
to relocate MacPorts to another directory if needed.
$ cd /opt/mports/macports-base $ ./configure --enable-readline $ make $ sudo make install $ make distclean
(Optional) Configure MacPorts to use port information from Git
This step is useful if you want to do port development. Check out the ports tree from git:
$ cd /opt/mports $ git clone https://github.com/macports/macports-ports.git
Then open /opt/local/etc/macports/sources.conf
in a text editor.
The last line should look like this:
rsync://rsync.macports.org/macports/release/tarballs/ports.tar [default]
Change it to point to the working copy you checked out:
file:///opt/mports/macports-ports [default]
Now MacPorts will look for portfiles in the working copy and use Git instead of rsync to update your ports tree.
Environment
You should setup your PATH and other environment options according to Section 2.5, “MacPorts and the Shell”.
Occasionally a MacPorts developer may wish to install more than one MacPorts instance on the same host.
Only one copy of MacPorts may use the default prefix /opt/local
, so for additional installations use the option --prefix
as shown below.
It’s also recommended to change the applications dir using --with-applications-dir
to avoid conflicts in /Applications/MacPorts
.
Use --without-startupitems
to automatically set startupitem_install no
in the new macports.conf
, which is required to avoid conflicts in /Library/LaunchAgents
or /Library/LaunchDaemons
.
The first command temporarily removes the standard MacPorts binary paths because they must not be present while installing a second instance.
$ export PATH=/bin:/sbin:/usr/bin:/usr/sbin $ MP_PREFIX=/opt/macports-test $ ./configure --prefix=$MP_PREFIX --with-applications-dir=$MP_PREFIX/Applications --without-startupitems $ make $ sudo make install