Building FreeBSD packages

This is a quick reciepe to (re)build FreeBSD packages from source so you can install them on another host which does not have ports installed.

At first we update our ports tree with portsnap fetch update:

# portsnap fetch update
[...]
Building new INDEX files... done.

Make sure the package to be built is not locked. You can list the locked packages with pkg lock -l:

# pkg lock -l
Currently locked packages:
freeradius-2.2.7
openldap-server-2.4.41

And unlock with pkg unlock <package-version>:

# pkg unlock freeradius-2.2.7
freeradius-2.2.7: unlock this package? [y/N]: y
Unlocking freeradius-2.2.7

Then we remove the old installation via make deinstall in the port's directory:

# cd /usr/ports/net/freeradius2
# make deinstall
===>  Deinstalling for freeradius
===>   Deinstalling freeradius-2.2.7
Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 1 packages (of 0 packages in the universe):

Installed packages to be REMOVED:
        freeradius-2.2.7

The operation will free 10 MiB.
[1/1] Deinstalling freeradius-2.2.7...
==> You should manually remove the "freeradius" user.
[1/1] Deleting files for freeradius-2.2.7: 100%

As next step we compile and install the new version with make install clean:

# make install clean
[...]
===>  Cleaning for freeradius-2.2.8

To prevent our port to be overwritten from a binary package we lock it again with pkg lock <package>:

# pkg lock freeradius
freeradius-2.2.8: lock this package? [y/N]: y
Locking freeradius-2.2.8

Finally we create the package with pkg create:

# cd
# pkg create freeradius
Creating package for freeradius-2.2.8

We can now distribute the created .txz file to other hosts and install it via pkg install <package-version>.txz.