Published : 2014-11-11

Ports management

FreeBSD is built around a system of ports and packages. This tutorial covers ports management on FreeBSD so you know how to install, use, compile, and manage the various ports. The strength of FreeBSD lies in the modularity of its ports.

Common Usage

The Ports Tree

The ports tree contains all the software. It is essential for service operation and updates, in order to do things properly under FreeBSD. It is split into categories (databases, www, converters…).

Fetching the Main Ports Snapshot

The first interesting command is portsnap. It synchronizes the FreeBSD ports snapshot with the distribution tree. The snapshot is incremental and contains the entire ports tree.

portsnap fetch

This command fetches the ports tree from the FreeBSD repository and synchronizes the local archive.

portsnap extract

This command extracts the ports tree. It only needs to be run the first time.

Updating the Ports Tree

To update the ports tree, simply run:

portsnap fetch update

Managing Updates

To manage updates there are two very powerful utilities: portupgrade and portmaster. Here we’ll use portmaster, which is more convenient. To install it:

cd /usr/ports/port-mgmt/portmaster
make install clean

To update the FreeBSD ports, simply run:

portmaster -a

System Update

To update the system you have the freebsd-update command:

freebsd-update fetch install

Rebuilding All Ports

After an OS version migration your services may become unstable — it’s even recommended to do this in that case. Rebuilding all ports becomes necessary:

portmaster -af

Managing a Port

Searching for a Port

To search for a port, simply run as root:

whereis <portname>

Example:

whereis mysql55-server

The path to the port is shown next. If you don’t know the port name, use the following command sequence:

cd /usr/ports
make search name=<str>

Installing a Port

To install a port, go into its directory and run make install clean:

cd /usr/ports/databases/mysql55-server
make install clean

make will compile; the install argument copies the binaries and libraries into the system directories; and clean removes the build files so they don’t take up too much disk space.

For some ports, the first build (or after changing build options in a ports tree update) will display a configuration dialog.

Uninstalling a Port

A single command is enough (it does not remove configuration files):

make deinstall

Reconfiguring a Port

If you got the build options wrong, or you need to enable new features, run the following:

make config

Known Issues

If you get the following error during portsnap fetch update:

metadata is corrupt

Your archive may be corrupted. Delete the ports tree and extract it again. This does not remove port configuration:

rm -R /var/db/portsnap/
portsnap fetch extract