1. Introduction
2. Installing MacPorts
2.1. Install Xcode
2.2. Install MacPorts
2.3. Upgrade MacPorts
2.4. Uninstall MacPorts
2.5. MacPorts and the Shell
3. Using MacPorts
3.1. The port Command
3.2. Port Variants
3.3. Common Tasks
3.4. Port Binaries
4. Portfile Development
4.1. Portfile Introduction
4.2. Creating a Portfile
4.3. Example Portfiles
4.4. Port Variants
4.5. Patch Files
4.6. Local Portfile Repositories
4.7. Portfile Best Practices
4.8. MacPorts' buildbot
5. Portfile Reference
5.1. Global Keywords
5.2. Global Variables
5.3. Port Phases
5.4. Dependencies
5.5. Variants
5.6. Tcl Extensions & Useful Tcl Commands
5.7. StartupItems
5.8. Livecheck / Distcheck
5.9. PortGroups
5.10. PortGroup Introduction
5.11. PortGroup github
5.12. PortGroup gnustep
5.13. PortGroup golang
5.14. PortGroup haskell
5.15. PortGroup java
5.16. PortGroup perl5
5.17. PortGroup python
5.18. PortGroup ruby
5.19. PortGroup xcode
6. MacPorts Internals
6.1. File Hierarchy
6.2. Configuration Files
6.3. Port Images
6.4. APIs and Libs
6.5. The MacPorts Registry
6.6. Tests
7. MacPorts Project
7.1. Using Trac for Tickets
7.2. Using Git and GitHub
7.3. Contributing to MacPorts
7.4. Port Update Policies
7.5. Updating Documentation
7.6. MacPorts Membership
7.7. The PortMgr Team
8. MacPorts Guide Glossary
Glossary

Chapter 3. Using MacPorts

This chapter describes using +port+, port variants, common tasks and port binaries.

3.1. The port Command

+port+ is the main utility used to interact with MacPorts. It is used to update [path]`Portfile`s and the MacPorts infrastructure, and install and manage ports.

3.1.1. port help

The help action shows some brief information about the specified action, or if no action is specified, shows basic usage information for +port+ in general.

$ port help selfupdate
Usage: selfupdate --no-sync

Upgrade MacPorts itself and run the sync target

--no-sync   Do not run the sync target, i.e., do not update the ports tree.
           Only checks for (and installs, if available) new versions of
           MacPorts.

3.1.2. port selfupdate

The selfupdate action should be used regularly to update the local ports tree with the global MacPorts ports repository so you will have the latest versions of software packages available. It also checks for new releases of MacPorts itself, and upgrades it when necessary.

$ sudo port selfupdate
---> Updating MacPorts base sources using rsync
MacPorts base version 2.6.2 installed,
MacPorts base version 2.6.2 downloaded.
---> Updating the ports tree
---> MacPorts base is already the latest version

If selfupdate detects that a newer version of MacPorts is available, it automatically updates the installed copy of MacPorts base to the latest released version. In that case, you will see this message:

---> Updating MacPorts base sources using rsync
MacPorts base version 2.6.1 installed,
MacPorts base version 2.6.2 downloaded.
---> Updating the ports tree
---> MacPorts base is outdated, installing new version 2.6.2
Installing new MacPorts release in /opt/local as root:admin; permissions 755

If the selfupdate procedure fails you’ll see a message like this:

Error installing new MacPorts base: command execution failed

As always, you can use the debug flag -d to enable verbose output. If your selfupdate failed, re-run it with debug output enabled to see all output generated by the build system.

$ sudo port -d selfupdate

The output may give you an idea why the build failed. Look for the first occurrences of error. If you cannot figure out what’s wrong yourself, feel free to ask on the macports-users@lists.macports.org mailing list and attach the output generated by +sudo port -d selfupdate+.

selfupdate accepts a single switch:

--no-sync
Only update MacPorts itself, do not update the tree of [path]`Portfile`s.

3.1.3. port sync

The sync action performs a subset of +selfupdate+. It synchronizes the ports tree, as does +selfupdate+, but it does not check for MacPorts upgrades. On macOS, unless there is a special reason not to do so, run selfupdate instead.

sync does not accept any switches.

3.1.4. port diagnose

The diagnose action checks for common issues in the user’s environment and reports all issues it finds to the user, along with possible fixes for said problem.

diagnose accepts a single switch:

--quiet
Only displays warnings and errors, rather than the status of all tests run.

3.1.5. port reclaim

The reclaim action attempts to reclaim space by uninstalling inactive ports, and removing unnecessary files that were downloaded during the installation process.

reclaim accepts switches to configure automatic reminders. If passed, the reclaim process will not be run.

--enable-reminders
Enable regular reminders to run +port reclaim+.
--disable-reminders
Disable regular reminders to run +port reclaim+.

3.1.6. port list

The list action lists the currently available version of the specified ports, or if no ports are specified, displays a list of all available ports. The list of available ports is very long, so use search if you are looking for a specific port.

$ port list

Note

+port list+ always lists the most recent version available in MacPorts, which is not necessarily the version you have installed. For this reason, +port list installed+ likely produces unexpected output. In most cases where you would +list+, using installed or echo is the better choice instead. Both +port installed+ and +port echo installed+ would produce the output you might expect from the command, +port list installed+ will not (and, to make matters worse, will be slow).

You will hardly need +port list+ at all to work with MacPorts. When searching, +port search+ is the better choice and when trying to list ports, +port installed+ and +port echo+ are much more useful.

3.1.7. port search

The search action allows finding ports by partial matches of the name or description. Other fields can be matched against, and matched in different ways, by using options. +port search+ is the tool of choice if you are looking for a specific software in MacPorts. We recommend you read up on some of its flags to improve your efficiency when searching for ports. Run +port help search+ for an exhaustive list of possible switches.

Suppose you are looking for PHP in MacPorts. You might start with +port search php+ and notice your query produces a lot of output. In fact, at the time of writing this, this search produces 661 matches. By default, +port search+ searches both name and description of a port. While we’re looking for PHP, we can reduce the number of hits by using the --name flag. Furthermore, we only want ports whose name starts with php, so we add the --glob flag (actually, we could leave it out because it is the default) and modify the search term to +php*+:

$ port search --name --glob 'php*'

Furthermore, we can enable compact output by using the --line switch. This causes only a single line to be printed for each match:

$ port search --name --line --glob 'php*'

Among a large number of PHP modules you will find the main PHP ports, which are named php<version>. Choose one to install.

If you know regex and know about the format of the PHP versions, you can further reduce the output of +port search+:

$ port search --name --line --regex '^php\d*$'
php     5.5       lang www    PHP: Hypertext Preprocessor
php4    4.4.9     lang www    PHP: Hypertext Preprocessor
php5    5.3.28    lang www    PHP: Hypertext Preprocessor
php52   5.2.17    lang www    PHP: Hypertext Preprocessor
php53   5.3.28    lang www    PHP: Hypertext Preprocessor
php54   5.4.31    lang www    PHP: Hypertext Preprocessor
php55   5.5.15    lang www    PHP: Hypertext Preprocessor
php56   5.6.0RC2  lang www    PHP: Hypertext Preprocessor

Let us look at another example that is less complicated. Assuming you are looking for +rrdtool+, a popular system to store and graph time-series data, the simple search approach works well:

$ port search rrd
cacti @0.8.8b (net)
    Cacti is a complete RRDtool network graphing solution.

jrrd @1.0.4 (java)
    Java interface to RRDTool

netmrg @0.20 (net)
    An RRDtool frontend for network monitoring, reporting, and graphing that generates day/week/month
    MRTG style graphs.

network-weathermap @0.97c (net)
    Weathermap is a network visualisation tool, to take graphs you already have and display an
    overview of your network as a map. It supports RRD, MRTG (RRD and old log-format), and
    tab-delimited text files. Other sources are via plugins or external scripts.

php-rrd @1.1.3 (php, net, devel)
    PHP rrdtool extension

php5-rrd @1.1.3 (php, net, devel)
    PHP rrdtool extension

php5-rrdtool @1.0.5 (php, net, devel)
    this port is only a stub and has been made obsolete by php5-rrd

php53-rrd @1.1.3 (php, net, devel)
    PHP rrdtool extension

php54-rrd @1.1.3 (php, net, devel)
    PHP rrdtool extension

php55-rrd @1.1.3 (php, net, devel)
    PHP rrdtool extension

rrdtool @1.4.7_5 (net)
    Round Robin Database

Found 11 ports.

The possible switches to search and their meaning are:

--case-sensitive
Match the search string in a case-sensitive manner.
--exact
Match the literal search string exactly.
--glob
Treat the given search string as glob search string (i.e., expand wildcards +\*+, +?+, and +[chars]+). This is the default behavior.
--regex
Treat the given search string as regular expression.
--field
Test the search string against +<field>+. Can be specified multiple times to test against multiple fields. The default is +--name --description+. Possible values for <field> are
+--category+, --categories
Search for ports in a given category.
+--depends+, +--depends_build+, +--depends_extract+, +--depends_fetch+, +--depends_lib+, --depends_run
Search for ports that depend on the port given as search string. The --depends is an alias for all other --depends_ options combined. Note that only dependencies specified in default variants will be found.
+--description+, --long_description
Test the search string against ports' descriptions.
--homepage
Test the search string against the homepage field of all ports.
+--maintainer+, --maintainers
Search for ports maintained by a specific maintainer.
--name
Search only ports' names.
--portdir
Test the search string against the path of the directory that contains the port.
+--variant+, --variants
Search for variant names.

3.1.8. port info

The info action is used to get information about a port: name, version, description, variants, homepage, dependencies, license, and maintainers.

$ port info yubico-pam
yubico-pam @2.16 (security)
Variants:             universal

Description:          The Yubico PAM module provides an easy way to integrate the YubiKey into your
                      existing user authentication infrastructure. The module can be configured to
                      validate YubiKeys against Yubico's YubiCloud infrastructure, a custom YubiKey
                      validation server or it can be used for offline authentication with newer
                      YubiKeys supporting a challenge-response protocol.
Homepage:             https://github.com/Yubico/yubico-pam

Build Dependencies:   pkgconfig, autoconf, automake, libtool
Library Dependencies: ykpers, yubico-c-client
Platforms:            darwin
License:              BSD
Maintainers:          cal@macports.org

3.1.9. port deps

The deps action lists the dependencies of a port. Dependencies are the packages are required by a port at runtime (library and runtime dependencies) or required to install it (build, fetch, and extract dependencies).

$ port deps apache2
Full Name: apache2 @2.2.27_0+preforkmpm
Library Dependencies: apr, apr-util, expat, openssl, pcre, perl5, zlib

Note that the list of dependencies might depend on the variants you chose. For example, choosing the \+openldap variant of apache2 adds a dependency on +openldap+:

$ port deps apache2 +openldap
Full Name: apache2 @2.2.27_0+openldap+preforkmpm
Library Dependencies: apr, apr-util, expat, openssl, pcre, perl5, zlib, openldap

deps accepts two switches:

--index
Do not read the Portfile to determine dependencies. Instead, rely on the information cached in the port index. Note that (despite specifying them), this option will ignore any effects of variants. It is, however, much faster.
--no-build
Exclude dependencies only required at build time, i.e., fetch, extract, and build dependencies.

3.1.10. port variants

The variants action allows you to check what variations of a port are available before you install it. Variants are a way for port authors to provide options you can use to customize your build at install time. See Invoking Port Variants below to install ports that have variants.

$ port variants apache2 +universal
apache2 has the variants:
   eventmpm: Use event MPM (experimental)
     * conflicts with preforkmpm workermpm
   openldap: Enable LDAP support through OpenLDAP
[+]preforkmpm: Use prefork MPM
     * conflicts with eventmpm workermpm
  +universal: Build for multiple architectures
   workermpm: Use worker MPM
     * conflicts with eventmpm preforkmpm

This output lists all variants followed by their description. If a variant depends on or conflicts with other variants, a line detailing that follows. A variant name prefixed by + indicates that it has been enabled (on the command line), while a prefix - indicates that it has been disabled. When bracketed, a prefix \+ means that the variant is enabled by default. Any [] are derived from the Portfile. While () are derived from the variants.conf. See Section 6.2.3, “variants.conf” for more information on variants.conf.

3.1.11. port install

The action install is used to install a port. Once you determined the name of a port you want (possibly using +port search+), you can install it using this command. See Section 3.2.1, “Invoking Variants” on how to choose variants when installing a new port. For example,

$ sudo port install apache2 -preforkmpm +workermpm

installs the apache2 port without the +preforkmpm+, but with the workermpm variant.

If the installation of a port fails, you can enable verbose or debug output by giving the -v or -d flag to port:

$ sudo port -v install apache2

All debug information is also kept in main.log for the port you installed. Its path will be printed automatically if the installation fails. You can manually get the path using +port logfile portname+. Note that logfiles will automatically be deleted on successful installation.

If the installation of a port fails, you should always clean and try again, i.e., run

$ sudo port clean portname

and re-execute the command you ran before.

You might also want to try enabling trace mode, which can prevent conflicts caused by files installed by other ports or in common system locations, such as /usr/local. To do that, re-run the installation with the -t flag, i.e.,

$ sudo port -t install portname

If the port still fails to install after you have followed these steps, please file a ticket and attach the main.log of a clean attempt.

Note

The installation of a single port consists of multiple phases. These phases are fetch, extract, patch, configure, build, destroot, archive, and finally install. You may break up a port’s installation into smaller steps for troubleshooting by using the name of one of these phases as action rather than +install+. For example

$ sudo port destroot apache2

will run the installation of apache2 until the destroot phase. See Section 5.3, “Port Phases” for a complete list of phases and a detailed description.

install takes the following switches:

--no-rev-upgrade
By default, a binary sanity check called rev-upgrade is run automatically after each successful installation. Pass this flag, if you want to avoid running this step, for example if you want to run it explicitly later after a number of installations using +sudo port rev-upgrade+, or if you know it will detect problems but want to defer dealing with them.
--unrequested
By default, each port you install using the install explicitly (contrary to ports installed as a dependency of a different port) is marked as requested. If you want MacPorts to treat a port you installed manually as if it was automatically installed as a dependency (e.g., if a dependency failed to build and you re-tried installing the dependency only), pass this flag.

3.1.12. port clean

The action clean deletes intermediate files created by MacPorts while installing a port. A +port clean+ is often necessary when builds fail and should be the first thing to try after a failed installation attempt.

$ sudo port clean portname

+port clean+ can also be used to remove corrupted downloads after a failed fetch phase, by specifying the --dist flag:

$ sudo port clean --dist portname

deletes all files that have been downloaded for the given port.

clean accepts the following options:

--archive
Remove temporary archives.
--dist
Remove downloaded files.
--logs
Remove log files.
--work
Remove the work directory, i.e., the directory used by MacPorts to build a software. This removes all traces of an attempted build and is the default operation.
--all
All of the above combined.

3.1.13. port uninstall

The uninstall action will remove an installed port. It is one of the actions you will use fairly often in MacPorts.

$ sudo port uninstall portname

MacPorts will refuse to uninstall ports that are still needed by other ports. For example:

$ sudo port uninstall libcomerr
--->  Unable to uninstall libcomerr @1.42.9_0, the following ports depend on it:
--->    kerberos5 @1.11.3_0
--->    subversion @1.8.9_0
--->    subversion-perlbindings-5.16 @1.8.9_0
Error: port uninstall failed: Please uninstall the ports that depend on libcomerr first.

You can recursively uninstall all ports that depend on the given port before uninstalling the port itself to work around this. To do that, use the --follow-dependents flag.

$ sudo port uninstall --follow-dependents libcomerr

You can also override this safety check using the -f (force) flag. Since this will obviously break the dependents you shouldn’t do this unless you know what you are doing.

$ sudo port -f uninstall libcomerr

Uninstalling a port will not uninstall ports that have been automatically installed as dependencies of the uninstalled port and are otherwise unused. You can trigger this behavior by passing the --follow-dependencies flag. Ports that were manually installed (i.e., are marked as requested) or have other dependents will not be removed. You can manually uninstall the unneeded ports later using the leaves pseudo-port, e.g., using +sudo port uninstall leaves+.

uninstall supports the following switches:

--follow-dependents
Recursively uninstall ports that depend on the specified port before uninstalling the port itself. See also the textual description above.
--follow-dependencies
Also uninstall ports that were automatically installed as dependencies of the removed port and are no longer needed.
--no-exec
Avoid running any uninstall hooks, such as commands that update cache files.

3.1.14. port contents

The contents action displays a list of all files that have been installed by a given port. You can only use contents for ports you installed.

$ port contents xorg-renderproto
Port xorg-renderproto contains:
  /opt/local/include/X11/extensions/render.h
  /opt/local/include/X11/extensions/renderproto.h
  /opt/local/lib/pkgconfig/renderproto.pc
  /opt/local/share/doc/renderproto/renderproto.txt

Common uses for contents are finding the location of a port’s executable after installing it. The following line is usually helpful in this case:

$ port -q contents portname | grep -E '/s?bin/'

The -q (quiet) flag suppresses the header line in this case, but is not strictly necessary.

contents accepts:

--size
Prints a human-readable representation of the files' sizes.
--units UNIT
Used in conjunction with --size to choose the unit of the file size. Valid parameters for UNIT are
B
List sizes in bytes.
+K+, +Ki+, or KiB
List sizes in +KiB+, i.e., 1024 bytes.
+Mi+, or MiB
List sizes in +MiB+, i.e., 1024 * 1024 bytes.
+Gi+, or GiB
List sizes in +GiB+, i.e., 1024 * 1024 * 1024 bytes.
+k+, or kB
List sizes in +kB+, i.e., 1000 bytes.
+M+, or MB
List sizes in +MB+, i.e., 1000 * 1000 bytes.
+G+, or GB
List sizes in +GB+, i.e., 1000 * 1000 * 1000 bytes.

3.1.15. port installed

The installed action displays the installed versions and variants of the specified ports, or if no ports are specified, all installed ports. It also displays whether a port is active, i.e., whether the files belonging to this port are currently present on disk or inactive, i.e., stashed away in a compressed tarball.

$ port installed
The following ports are currently installed:
  a52dec @0.7.4_0 (active)
  adns @1.4_0 (active)
  apache2 @2.2.27_0+preforkmpm (active)
  apr @1.5.1_0 (active)
  apr-util @1.5.3_0 (active)
  aquaterm @1.1.1_0 (active)
  asciidoc @8.6.9_1+python27 (active)
  …
  XviD @1.3.3_0 (active)
  xz @5.0.5_0 (active)
  yasm @1.2.0_0 (active)
  ykpers @1.12.0_0 (active)
  youtube-dl @2014.07.25.1_0+python27 (active)
  yubico-c-client @2.12_0 (active)
  yubico-pam @2.16_0 (active)
  zlib @1.2.8_0 (active)

Use -v to also display the platform and CPU architecture(s) for which the ports were built, and any variants which were explicitly negated.

$ port -v installed libsdl
The following ports are currently installed:
  libsdl @1.2.15_3-x11 (active) platform='darwin 13' archs='x86_64'

3.1.16. port outdated

The outdated action checks your installed ports against the current ports tree to see they have been updated since you installed them. Note that you will only get new versions by updating your ports tree using <<using.port.selfupdate,selfupdate>> (or +sync+).

$ port outdated
The following installed ports are outdated:
gnupg                          1.4.16_0 < 1.4.18_0
gnupg2                         2.0.22_2 < 2.0.25_0
gpg-agent                      2.0.22_1 < 2.0.25_0
gpgme                          1.5.0_0 < 1.5.1_0
HexFiend                       2.1.2_1 < 2.3.0_0
libksba                        1.0.8_0 < 1.3.0_0
p5.16-class-methodmaker        2.180.0_1 < 2.210.0_0
p5.16-gnupg-interface          0.330.0_3 < 0.500.0_1
p5.16-ipc-run                  0.910.0_1 < 0.920.0_0

+port outdated+ lists the ports for which an upgrade is available and on the second column, why MacPorts thinks the port needs an upgrade. In most cases, this will be an increase in the version number. If it isn’t, more details will be given.

3.1.17. port upgrade

The upgrade action upgrades installed ports and their dependencies to the latest version available in MacPorts. In most cases, you will run

$ sudo port upgrade outdated

to update all ports that have an upgrade available. You can, however, selectively upgrade ports if you want to delay other upgrades until later. This is not recommended unless you know what you are doing, since you might experience software errors for the ports that have not yet been upgraded. To upgrade individual ports, specify the name(s) of the port(s) to upgrade:

$ sudo port upgrade gnupg2

Note that MacPorts may decide to upgrade other dependent ports before upgrading the port you requested to be updated. Do not attempt to prevent this, since it will very likely lead to problems later.

Note

upgrade does not uninstall the old version of a port. Instead, it deactivates it, i.e., it stashes the files belonging to the older version away in a tarball. This allows you to go back to the older version if there happens to be a problem with the updated one. To do that, run

$ port installed portname

to determine the version number of the old version you want to re-activate, and run

$ sudo port activate portname @old-version

to go back to the old version.

If you do not want to keep the old versions around while upgrading, you can pass -u when upgrading:

$ sudo port -u upgrade outdated

However, we instead recommend keeping the older versions around for a while and running

$ sudo port uninstall inactive

once in a while.

upgrade accepts a number of switches:

--force
Always consider the given ports outdated, regardless of whether they actually are.
--enforce-variants
If the installed variants do not match those requested, upgrade (and change variants) even if the port is not outdated. You can use this to switch the variant selection on an installed port, e.g., using
$ sudo port upgrade --enforce-variants apache2 -preforkmpm +workermpm

+ Note that --enforce-variants will also enforce your variant selection in all dependencies. If you know this is not necessary, you can avoid processing dependencies using the global -n flag:

+

$ sudo port -n upgrade --enforce-variants apache2 -preforkmpm +workermpm
--no-replace
Do not automatically install replacement ports for a port that you have installed, but was replaced with a different one.

3.1.18. port dependents

The dependents action reports what ports depend upon a given (installed) port, if any.

$ port dependents openssl
apache2 depends on openssl
curl depends on openssl
cyrus-sasl2 depends on openssl
git depends on openssl
kerberos5 depends on openssl
lftp depends on openssl
libssh depends on openssl
mosh depends on openssl
openldap depends on openssl
p5.16-net-ssleay depends on openssl
python27 depends on openssl
python32 depends on openssl
qt4-mac depends on openssl
ruby19 depends on openssl
serf1 depends on openssl
textmate2 depends on openssl
wireshark depends on openssl

Note that dependents does not work for ports that are not installed on your system. If you want to find out, which ports depend on a port that you have not installed, you can use

$ port echo depends:portname

This command will, however, not cover dependencies that are only present in non-default variants.

3.1.19. port livecheck

The livecheck action checks to see if the application corresponding to a given port has been updated at the developer’s download site. This action is mostly useful for port maintainers to determine whether their port needs to be updated, but other may also wish to see if a port packages the latest available version. See Section 5.8, “Livecheck / Distcheck” for more information on livecheck.

$ port livecheck rb19-sass
rb19-sass seems to have been updated (port version: 3.3.10, new version: 3.3.14)

Note

If livecheck finds no higher version at the port’s download site, it prints nothing. The option -d (debug) may be used for detailed livecheck processing information.

3.1.20. port lint

The lint action checks if the Portfile conforms to the MacPorts standards specified in Portfile Development. You should use this if you modified a Portfile before submitting patches back to MacPorts.

If a Portfile validates fine the following message is shown.

$ port lint rb19-sass
--->  Verifying Portfile for rb19-sass
--->  0 errors and 0 warnings found.

Otherwise the warnings and errors are listed.

$ port lint abiword
--->  Verifying Portfile for abiword
Warning: Variant use_binary does not have a description
Warning: Variant use_source does not have a description
Warning: no license set
--->  0 errors and 3 warnings found.

lint has the following flag:

--nitpick
Enables additional checks that are mostly whitespace-related and best practices.