August 23, 2024

There’s a common misconception that third-party software for FreeBSD must be built from source using the ports tree.  However, FreeBSD has long provided an official package collection, offering over 34,000 packages at the time of writing. The current package management tool, pkg(8), available since 2014, offers much more flexibility than the original pkg_install created by Jordan Hubbard in 1993.  Thus, for most users, installing software on FreeBSD using the official packages is more efficient and straightforward. 

FreeBSD Package Collection

The FreeBSD package collection is a repository of software users can quickly and easily install using pkg(8).  Here are some key points:

  1. Ease of Use: The primary advantage of the package collection is its simplicity. Users can install software with a single command, for example:

    pkg install firefox

This command fetches the package and installs it on your system, along with any necessary dependencies.

  1. Speed: Since packages are precompiled, installation is swift. There’s no need to compile the software from source, saving time and computational resources.
  2. Consistency: The FreeBSD project builds and tests binary packages, ensuring a consistent and reliable installation experience. This reduces the risk of encountering build errors or inconsistencies.
  3. Large Repository: The Package Collection includes over 34,000 software packages, covering a wide range of applications and utilities.
  4. Dependencies Handling: The pkg tool automatically handles dependencies, fetching and building them as needed. This ensures that all required components are correctly installed.
  5. Updates: Keeping software up-to-date is straightforward with the pkg tool. Users can upgrade all installed packages with a single command:

    pkg upgrade

Building your own packages from the ports tree

Advanced users, developers, and software testers might choose to build their own packages using the ports tree.

The FreeBSD ports tree and tools like poudriere offer advanced customization and optimization capabilities for users with specific needs. While the official packages provide simplicity and speed, ports allow for a highly tailored software management experience.

Why use ports?

  1. Customized Builds: Tailor software with specific compiler flags (CFLAGS) for optimized performance on your hardware.
  2. Feature Selection: Enable or disable specific features unavailable in the official packages.
  3. Dependency Control: Customizing port options allows some control over which dependencies are installed.
  4. Latest Versions: Access the most recent software versions before they become available as official packages.

Getting started

Fetch the Ports Collection using git:

pkg install git

git clone https://git.freebsd.org/ports.git /usr/ports

Building and installing custom packages from ports

Navigate to the desired port and build it (where category/port is the actual subdirectory of the package you’d like to build):

cd /usr/ports/category/port

make install clean

Advanced customization

If you want to customize the build to add compile time options, run the following before performing make install clean

cd /usr/ports/category/port make config

Creating packages

Create a binary package for distribution:

cd /usr/ports/category/port make package

Building ports/packages with Poudriere

poudriere is a tool for building and testing ports in clean environments, ideal for maintaining custom repositories. In combination with FreeBSD Jails, Poudriere ensures clean builds, avoiding host system contamination.

Install Poudriere:

pkg install poudriere

Create a Ports Jail (taking into consideration the version of FreeBSD you are using, with 14.1 as an example):

poudriere jail -c -j 14_1 -v 14.1-RELEASE

Build Packages:

poudriere bulk -j 14_1 -p default category/port

Conclusion

Whether you install third-party software on FreeBSD from the official package collection or you build custom packages from the ports tree depends on your needs and preferences:

  • Convenience and Speed: If you prefer a hassle-free installation process, use the official packages, especially if you are new to FreeBSD.
  • Customization and Control: If you are an advanced user or developer or need specific configurations, build custom packages using the ports tree. It provides greater control and flexibility, allowing for tailored builds and optimizations.

The FreeBSD package collection and ports tree are integral parts of the FreeBSD ecosystem. Understanding the advantages and drawbacks of either building custom packages or directly installing the official packages helps users make informed decisions about managing software on their FreeBSD systems, balancing convenience, customization, and control according to their needs.

For more detailed information, you can refer to the FreeBSD Handbook.