3. Packages and Ports: Adding Software in FreeBSD

FreeBSD provides two methods for installing applications: binary packages and compiled ports. Each method has its own benefits:

Binary Packages

If an application installation does not require any customization, installing the package is sufficient. Compile the port instead whenever an application requires customization of the default options. If needed, a custom package can be compiled from ports using make package.

A complete list of all available ports and packages can be found here.

3.1. Packages

Packages are pre-compiled applications, the FreeBSD equivalents of .deb files on Debian/Ubuntu based systems and .rpm files on Red Hat/Fedora based systems. Packages are installed using pkg. For example, the following command installs Apache 2.4:

# pkg install apache24

For more information on packages refer to section 5.4 of the FreeBSD Handbook: Using pkgng for Binary Package Management.

3.2. Ports

The FreeBSD Ports Collection is a framework of Makefiles and patches specifically customized for installing applications from source on FreeBSD. When installing a port, the system will fetch the source code, apply any required patches, compile the code, and install the application and any required dependencies.

The Ports Collection, sometimes referred to as the ports tree, can be installed to /usr/ports using portsnap(8) (if running FreeBSD 11.4 or 12.1) or Subversion (if running FreeBSD-CURRENT). Detailed instructions for installing the Ports Collection can be found in section 5.5 of the FreeBSD Handbook.

To compile a port, change to the port's directory and start the build process. The following example installs Apache 2.4 from the Ports Collection:

# cd /usr/ports/www/apache24
# make install clean

A benefit of using ports to install software is the ability to customize the installation options. This example specifies that the mod_ldap module should also be installed:

# cd /usr/ports/www/apache24
# make WITH_LDAP="YES" install clean

Refer to Using the Ports Collection for more information.

All FreeBSD documents are available for download at https://download.freebsd.org/ftp/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.