PORTS(7)

πŸ“¦
version 15.1 Β· 4 versions
, in freebsd 15.1

πŸ’… PORTS(7) πŸ’…

miscellaneous information manual β€’ ports β€” contributed applications

🌸 NAME 🌸

ports β€” contributed applications.

✨ DESCRIPTION ✨

okay so the FreeBSD Ports Collection is literally the simple way to compile and install third party applications. It is also used to build packages, to be installed using pkg(8).

The ports tree, typically located at /usr/ports, consists of subdirectories, one for each category; those in turn contain individual ports. Each port is a directory with metadata and patches necessary to make the original application source code compile and run on FreeBSD. Compiling an application is as simple as typing make build in the port directory. The Makefile automatically fetches the application source code, either from a local disk or the network, unpacks it, applies the patches, and compiles it. It also recursively handles dependencies β€” other pieces of software the port depends on in order to build and work. Afterwards, make install installs the application.

The FreeBSD Ports Collection is maintained in several branches, which differ mostly by versions of software provided: the main branch contains all the latest changes and corresponds to the latest package set, while the quarterly branches only provide critical fixes. The main branch can be cloned and updated from the Git repository located at:

https://git.FreeBSD.org/ports.git

so eg:

git clone https://git.FreeBSD.org/ports.git

The quarterly branches can be found in Git as branches like yyyyQn, where yyyy indicates the year and n indicates the quarter (1 to 4), eg:

git clone -b 2021Q2 https://git.FreeBSD.org/ports.git

It is generally a good idea to use the ports branch that matches the pkg(8) repository being used. By default, for FreeBSD CURRENT the pkg(8) is configured to install packages built from the main branch, while for FreeBSD STABLE or RELEASE versions it is configured to install packages built from the latest quarterly branch. Currently configured pkg(8) repository can be verified by looking at the url field in pkg -vv output. iykyk πŸ‘€

For more information about using ports, see the β€œPackages and Ports section” in The FreeBSD Handbook:

https://docs.FreeBSD.org/en/books/handbook/ports/

For information about creating new ports, see The Porter's Handbook:

https://docs.FreeBSD.org/en/books/porters-handbook/

πŸŽ€ TARGETS πŸŽ€

Some of the make(1) targets work recursively through subdirectories. This lets you, for example, install all of the β€œbiology” ports with one command. The targets that do this are build, checksum, clean, configure, depends, extract, fetch, install, and package.

The following targets will be run automatically by each proceeding target in order. That is, build will be run (if necessary) by install, and so on all the way to fetch. Usually, you will only use the install target.

🌈 the auto-run chain

  • config β€” Configure OPTIONS for this port using portconfig(1) (ports/ports-mgmt/portconfig).
  • fetch β€” Fetch all of the files needed to build this port from the sites listed in MASTER_SITES and PATCH_SITES. See FETCH_CMD, MASTER_SITE_OVERRIDE and MASTER_SITE_BACKUP.
  • checksum β€” Verify that the fetched distfile's checksum matches the one the port was tested against. If the distfile's checksum does not match, it also fetches the distfiles which are missing or failed the checksum calculation. Defining NO_CHECKSUM will skip this step.
  • depends β€” Install (or compile if only compilation is necessary) any dependencies of the current port. When called by the extract or fetch targets, this is run in piecemeal as fetch-depends, build-depends, etc. Defining NO_DEPENDS will skip this step.
  • extract β€” Expand the distfile into a work directory.
  • patch β€” Apply any patches that are necessary for the port.
  • configure β€” Configure the port. Some ports will ask you questions during this stage. See INTERACTIVE and BATCH.
  • build β€” Build the port. This is the same as calling the all target.
  • install β€” Install the port and register it with the package system. This is all you really need to do.
  • install-missing-packages β€” Install missing dependencies from packages instead of building them.

🚫 not run during the normal install process

The following targets are not run during the normal install process.

  • showconfig β€” Display OPTIONS config for this port.
  • showconfig-recursive β€” Display OPTIONS config for this port and all its dependencies.
  • rmconfig β€” Remove OPTIONS config for this port.
  • rmconfig-recursive β€” Remove OPTIONS config for this port and all its dependencies.
  • config-conditional β€” Skip the ports which have already had their OPTIONS configured.
  • config-recursive β€” Configure OPTIONS for this port and all its dependencies using portconfig(1) (ports/ports-mgmt/portconfig).
  • fetch-list β€” Show the list of files to fetch in order to build the port (but not its dependencies).
  • fetch-recursive β€” Fetch the distfiles of the port and all its dependencies.
  • fetch-recursive-list β€” Show list of files that would be retrieved by fetch-recursive.
  • build-depends-list, run-depends-list β€” Print a list of all the direct compile or run dependencies for this port.
  • all-depends-list β€” Print a list of all recursive dependencies for this port.
  • pretty-print-build-depends-list, pretty-print-run-depends-list β€” Print a list of all the recursive compile or run dependencies for this port by port name and version.
  • missing β€” Print a list of missing dependencies to be installed for the port.
  • clean β€” Remove the expanded source code. This recurses to dependencies unless NOCLEANDEPENDS is defined.
  • distclean β€” Remove the port's distfiles and perform the clean target. The clean portion recurses to dependencies unless NOCLEANDEPENDS is defined, but the distclean portion never recurses (this is perhaps a bug).
  • reinstall β€” Use this to restore a port after using pkg-delete(8) when you should have used deinstall.
  • deinstall β€” Remove an installed port from the system, similar to pkg-delete(8).
  • deinstall-all β€” Remove all installed ports with the same PKGORIGIN from the system.
  • package β€” Make a binary package for the port. The port will be installed if it has not already been. The package is a .pkg file that you can use to install the port on other machines with pkg-add(8). If the directory specified by PACKAGES does not exist, the package will be put in /usr/ports/category/port/work/pkg. See PKGREPOSITORY and PKGFILE for more information.
  • package-recursive β€” Like package, but makes a package for each depending port as well.
  • package-name β€” Prints the name with version of the port.
  • readmes β€” Create a port's README.html. This can be used from /usr/ports to create a browsable web of all ports on your system!
  • search β€” Search the INDEX file for the pattern specified by the key (searches the port name, comment, and dependencies), name (searches the port name only), path (searches the port path), info (searches the port info), maint (searches the port maintainer), cat (searches the port category), bdeps (searches the port build-time dependency), rdeps (searches the port run-time dependency), www (searches the port web site) make(1) variables, and their exclusion counterparts: xname, xkey etc.

For example, one would type:

cd /usr/ports && make search name=query

to find all ports whose name matches β€œquery”. Results include the matching ports' path, comment, maintainer, build dependencies, and run dependencies.

cd /usr/ports && make search name=pear- \
    xbdeps=apache

To find all ports whose names contain β€œpear-” and which do not have apache listed in build-time dependencies.

cd /usr/ports && make search name=pear- \
    xname='ht(tp|ml)'

To find all ports whose names contain β€œpear-”, but not β€œhtml” or β€œhttp”.

make search key=apache display=name,path,info keylim=1

To find ports that contain β€œapache” in either of the name, path, info fields, ignore the rest of the record.

By default the search is not case-sensitive. In order to make it case-sensitive you can use the icase variable:

make search name=p5-R icase=0
  • quicksearch β€” Reduced search output. Only display name, path and info.
  • describe β€” Generate a one-line description of each port for use in the INDEX file.
  • maintainer β€” Display the port maintainer's email address.
  • index β€” Create /usr/ports/INDEX, which is used by the pretty-print-* and search targets. Running the index target will ensure your INDEX file is up to date with your ports tree.
  • fetchindex β€” Fetch the INDEX file from the FreeBSD cluster.

πŸ’– ENVIRONMENT πŸ’–

Okay so you can change literally all of these, bestie β€” no cap.

  • PORTSDIR β€” where the ports tree lives. Defaults to /usr/ports. ✨
  • WRKDIRPREFIX β€” where temporary files get created. Super useful when PORTSDIR is read-only (like maybe it's mounted from a CD-ROM, iconic but restrictive).
  • DISTDIR β€” where to find/put distfiles, normally distfiles/ inside PORTSDIR.
  • SU_CMD β€” the command used to elevate privilege so you can configure and install a port. The unprivileged user must have write access to WRKDIRPREFIX and DISTDIR. Default is /usr/bin/su root -c. Lots of people set it to /usr/local/bin/sudo -E sh -c because convenience slays.
  • PACKAGES β€” only used for the package target; base directory for the packages tree, normally packages/ in PORTSDIR. If this directory exists, the package tree will be (partially) constructed. It does not have to exist; if it doesn't, packages go into the current directory, or you can define one of:
    • PKGREPOSITORY β€” directory to put the package in.
    • PKGFILE β€” the full path to the package.
  • LOCALBASE β€” where existing things are installed and where to search for files when resolving dependencies (usually /usr/local).
  • PREFIX β€” where to install this port (usually set to the same as LOCALBASE).
  • MASTER_SITES β€” primary sites for distribution files if they're not found locally.
  • PATCH_SITES β€” primary locations for distribution patch files if they're not found locally.
  • MASTER_SITE_FREEBSD β€” if set, go to the master FreeBSD site for all files.
  • MASTER_SITE_OVERRIDE β€” try going to these sites for all files and patches, first.
  • MASTER_SITE_BACKUP β€” try going to these sites for all files and patches, last.
  • RANDOMIZE_MASTER_SITES β€” try the download locations in a random order.
  • MASTER_SORT β€” sort the download locations according to a user-supplied pattern. Example:
.dk .sunet.se .se dk.php.net .no .de
heanet.dl.sourceforge.net
  • MASTER_SITE_INDEX β€” where to get the INDEX source built on the FreeBSD cluster (for the fetchindex target). Defaults to https://download.FreeBSD.org/ports/index/.
  • FETCHINDEX β€” command to get INDEX (for the fetchindex target). Defaults to fetch -am.
  • NOCLEANDEPENDS β€” if defined, do not let clean recurse to dependencies.
  • FETCH_CMD β€” command to use to fetch files. Normally fetch(1).
  • FORCE_PKG_REGISTER β€” if set, overwrite any existing package registration on the system.
  • INTERACTIVE β€” if defined, only operate on a port if it requires interaction.
  • BATCH β€” if defined, only operate on a port if it can be installed 100% automatically.
  • DISABLE_VULNERABILITIES β€” if defined, disable the check for security vulnerabilities using pkg-audit(8) when installing new ports.
  • NO_IGNORE β€” if defined, allow installation of ports marked as ⟨FORBIDDEN⟩. The default behavior of the Ports framework is to abort when someone tries to install a forbidden port. Of course, these ports may not work as expected, but if you really know what you're doing and are sure about installing a forbidden port, then NO_IGNORE lets you do it. πŸ™ˆ
  • NO_CHECKSUM β€” if defined, skip verifying the port's checksum.
  • TRYBROKEN β€” if defined, attempt to build a port even if it's marked as ⟨BROKEN⟩.
  • PORT_DBDIR β€” directory where the results of configuring OPTIONS are stored. Defaults to /var/db/ports. Each port where OPTIONS have been configured gets a uniquely named sub-directory containing a single file called options.

✨ MAKE VARIABLES ✨

The following list gives a name and short description for many of the variables used when building ports. More info on these and other related variables can be found in ${PORTSDIR}/Mk/* and the FreeBSD Porter's Handbook. πŸ“š

  • WITH_DEBUG β€” (bool) if set, debugging symbols are installed for ports binaries.
  • WITH_DEBUG_PORTS β€” a list of origins for which to set WITH_DEBUG.
  • DEBUG_FLAGS β€” (Default: -g) additional CFLAGS to set when WITH_DEBUG is set.
  • DEFAULT_VERSIONS β€” override the default variant used for ports with multiple concurrent versions in the tree, such as database or compiler versions.
  • WITH_CCACHE_BUILD β€” (bool) if set, enables the use of ccache(1) for building ports.
  • CCACHE_DIR β€” which directory to use for the ccache(1) data.

πŸŽ€ FILES πŸŽ€

These are the spots you'll be poking around in, bestie:

  • ports/CHANGES β€” BREAKING NEWS to read before creating ports!
  • ports/CONTRIBUTING.md β€” instructions for contributing to the ports tree.
  • ports/Mk/bsd.port.mk β€” the inner workings of the ports framework.
  • ports/Tools/scripts/ β€” grab bag of tools for maintaining ports.
  • ports/UPDATING β€” BREAKING NEWS to read before upgrading ports!
  • ports/distfiles/ β€” directory where fetched files are stored.

Inside a specific port, ${PORT}:

  • ${PORT}/Makefile β€” specification for building the port.
  • ${PORT}/distinfo β€” checksums generated with make makesum.
  • ${PORT}/files/ β€” directory for patches or any additional files.
  • ${PORT}/pkg-descr β€” long description of the port.
  • ${PORT}/pkg-plist β€” list of all files installed by the port.
  • ${PORT}/work/ β€” the port's building and staging directory.

System spots:

  • /etc/make.conf β€” settings for the port-building framework.
  • /usr/ports/ β€” canonical ports tree location.
  • /var/db/ports/ β€” directory for storing configured OPTIONS.

πŸ¦‹ EXAMPLES πŸ¦‹

Example 1: Building and Installing a Port

The following command builds and installs Emacs. 🫢

# cd /usr/ports/editors/emacs
# make install

Example 2: Installing Dependencies with pkg(8)

This example shows how to build and install a port without having to build its dependencies. Instead, the dependencies are downloaded via pkg(8). Literally so convenient.

# make install-missing-packages
# make install

It's especially useful when the dependencies are costly in time and resources to build (like lang/rust). The drawback is that pkg(8) offers only packages built with the default set of OPTIONS. 😭

Example 3: Building a Non-Default Flavor of a Port

The following command builds a non-default flavor of a port. (In this case devel/py-pip is going to be built with Python 3.7 support.)

# cd /usr/ports/devel/py-pip
# env FLAVOR=py37 make build

Example 4: Setting Ports Options via make.conf(5)

The following lines present various ways of configuring ports options via make.conf(5) (as an alternative to, e.g., running make config):

# Enable NLS for all ports unless configured otherwise
# using the options dialog.
OPTIONS_SET=            NLS
# Disable DOCS for all ports overriding the options set
# via the options dialog.
OPTIONS_UNSET_FORCE=    DOCS
# Disable DOCS and EXAMPLES for the shells/zsh port.
shells_zsh_UNSET=       DOCS EXAMPLES

These and other options-related variables are documented in /usr/ports/Mk/bsd.options.mk.

Example 5: Setting make(1) Variables for Specific Ports via make.conf(5)

The following example shows how to set arbitrary make(1) variables only for specific ports:

# Set DISABLE_MAKE_JOBS for the lang/rust port:
.if ${.CURDIR:M*/lang/rust}
DISABLE_MAKE_JOBS=      yes
TRYBROKEN=              yes
.endif

Example 6: Debugging Ports

By default, ports are built and packaged without debugging support (e.g., debugging symbols are stripped from binaries, optimization flags are used for compiling, verbose logging is disabled). Whether ports are built with debugging symbols can be controlled by the settings in make.conf(5), e.g.:

# Enable debugging for all ports.
WITH_DEBUG=             yes
# Enable debugging for selected ports.
WITH_DEBUG_PORTS=       mail/dovecot security/krb5

It's also possible to use the debug variables on the command line:

# make WITH_DEBUG DEBUG_FLAGS="-g -O0" build

See the β€œMAKE VARIABLES” section to learn more about the debug variables.

To understand the details of what happens when the debug variables are set, it's best to consult the files located at ${PORTSDIR}/Mk/* (bsd.port.mk in particular).

If debugging is enabled for a specific port, the ports framework will:

  • Add DEBUG_FLAGS (defaults to -g) to CFLAGS.
  • Try to prevent the binaries from being stripped (including checking the install target to replace install-strip with install). Whether a binary has been stripped can be checked with file(1).
  • Try to enable other debugging features like debug build type or verbose logging. However, this is port-specific and the ports framework might not be aware of each supported debugging feature a given piece of software has to offer. 🫠

🌈 SEE ALSO 🌈

Additional developer documentation:

  • portlint(1)
  • /usr/ports/Mk/bsd.port.mk

Additional user documentation:


πŸ’œ HISTORY πŸ’œ

The Ports Collection appeared in FreeBSD 1.0. It has since spread to NetBSD, OpenBSD, and macOS. Iconic behavior, honestly. πŸ‘‘


πŸ‘‘ AUTHORS πŸ‘‘

This manual page was originated by David O'Brien.


πŸ’€ BUGS πŸ’€

Ports documentation is split over four places β€” /usr/ports/Mk/bsd.port.mk, The Porter's Handbook, the β€œPackages and Ports” chapter of The FreeBSD Handbook, and this manual page. Not me having to check four places, bestie 😭


That's the vibe check, bestie πŸ’… β€” signed off by Debian, dated February 24, 2026, on page PORTS(7) 🫢✨

πŸ“¦ where this page comes from