Using the ports system

Ports and Packages are the ways in which you install software onto a FreeBSD system. The third way is simply to obtain the source code and build from that - perfectly possible but slow, sometimes untidy, and lots of hard work, so only to be endured for certain vital components!

Packages - the command 'pkg_add -r mypackage' will download a pre-compiled version of mypackage and install it on the system. It really is that simple.

Ports are more interesting. The ports directory for your package, /usr/ports/allsortsofstuff/mypackage, contains everything you need to build the software from source except the source code itself. The routine is this:-

cd /usr/ports/allsortsofstuff/mypackage

  make WITH_GTK2=yes install clean

The system will then download the source, compile it, install the necessary files in the right places, and clean out the working directory.

While we are on ports, here are some useful commands for port administration.

To update the files in /usr/ports

  portsnap fetch update

To fix the package database, take care of stale dependencies etc

  pkgdb -F

To reveal which ports are eligible for updating.

portversion is even better for this purpose.

  pkg_version -L =

To upgrade packages individually just do

portupgrade emacs

To up-grade all your ports at one go ...

  portupgrade -akOP

Be warned - this can take a LONG time, more than a day, if you haven't kept the system up to date.

Wiping off all ports and starting again.

Because of FreeBSD's very clear distinction between the base system and the added ports, it is easy (though avery slow process) to wipe off all user application and re-build. Portmaster is the tool to use.

From 'man portmaster'

  1. portmaster -l > ~/installed-port-list
  2. Update your ports tree
  3. portmaster —clean-distfiles-all
  4. portmaster —check-port-dbdir
  5. portmaster -Faf
  6. pkg_delete '*'
  7. rm -rf /usr/local/lib/compat/pkg
  8. Manually check /usr/local and /var/db/pkg to make sure that they are really empty

Now look at the list you generated in the first step and install the root and leaf ports that you want to have again. The trunk and branch ports are dependencies, and will automatically be installed as needed. You probably want to use the -D option for the installations and then run —clean-distfiles[-all] again when you are done. You might also want to consider using the —force-config option when installing the new ports.

Back to FreeBSD page