Roland's homepage

My random knot in the Web

Automating package updates on FreeBSD

When updating my ports, I prefer to use packages when I have not changed the options of a port. This describes how I do that.


Compiling large programs like firefox can take a long time. Therefore I like to use packages when updating my ports. But I don’t want to loose any custom options I might have chosen.


This is basically divided into two parts,

  1. Finding out which ports can be updated by packages.
  2. Downloading and installing packages.

For the first part, we need to ascertain that the actual options used on a port (from pkg query) match the default values (from inspecting the value of the OPTIONS_DEFAULT “make” variable in the port). This is accomplished by the find-pkg-upgrades Python script. I will not cover it workings in more detail. Suffice it to say that it produces a list of port names that can be updated by a package.

For the second part, one could just run pkg upgrade. This however has some annoying side effects. For example it often tries to install Python 3.6, while I use 3.7. This is fair enough since 3.6 is the default, but I don’t need it. Often it also installs the deprecated Perl version 5.26, which annoys me to no end. And to the best of my knowledge the upgrade command does not have an option to force it to only upgrade the packages I specified. So I do the following.

  • Empty the package cache (/var/cache/pkg).
  • Use pkg fetch to get the new packages.
  • Use pkg delete -f to delete only the selected old packages.
  • Use pkg add to install the new packages from the package cache.

This ensures that only the packages I choose are updated. (These commands have been combined into a shell-script. Since this is rather trivial I didn’t bother putting it on github.)

←  Install ntpsec on FreeBSD