The ports tree is vaguely like a package system (like RPM). It is just a large number of files who just define changes to the source code of a particular “port”, where to get the port’s source code from, and options that can be set or unset during compilation. Gentoo took direct inspiration from the FreeBSD ports tree for their portage system.
Prior to version FreeBSD 6.x, the ports tree was kept up-to-date with the cvsup command. This is now being phased out in favor of a utility called portsnap. This portsnap utility aims to make it much easier to maintain an up-to-date ports tree, and it seems to be true. If you are using a version of FreeBSD prior to 6.x, the portsnap utility will have to be loaded from ports before you can use it.
To start maintaining a port with portsnap:
portsnap fetch extract
To update the ports tree:
portsnap fetch update
Another common utility used to manage ports is the portupgrade command. However, portupgrade is a port, so you will have to install it first. The portupgrade utility will help you maintain your system and keep installed ports current. There is also the portversion command, included with portupgrade, which will list installed ports and their status relative to the current port (newer, older, equivalent, etc.).
To keep the portupgrade database valid and current, use this command on a regular basis (perhaps from cron):
This will fetch the INDEX file from upstream and then recreate the local database file used by portupgrade. A (much slower) alternative is to create the INDEX file from the local ports:
However, with a decent internet connection the -F option will be faster.
On occasion, the portupgrade database may become corrupted, or their may be unresolvable conflicts between the ports tree and an installed port. To resolve these issues, issue this command:
This will check the database and ask you to resolve any problems that may occur. Daniel Reinholz has an excellent article on how to understand and use pkgdb -F available.
The portsclean command cleans out all of the detritus that gets left behind during ports installation at times. The best command is probably:
This will remove all working directories left in the ports tree (the -C option specifies this) and will remove archives from the distfiles directory (the -D option) which are not in the ports tree.
With this combination of tools, I would suggest the following crontab entries (assuming a decently fast always-on internet connection):
1 3 * * * portsclean -CD
2 4 * * * portsnap fetch update && pkgdb -u
This will keep the ports tree updated nightly, as well as the portupgrade database.
There is a lot more information available out there. Papa Mike IT Services has not one but two excellent articles: one on updating and upgrading ports, and one on basic port management. Be sure to read the articles all the way through and don’t miss the links at the bottom.
Over at My Digital Life, there is an excellent tutorial on using portsnap. It covers not only the basics, but all the rest as well.
If you are looking for ports online, you can get information from FreshPorts or directly from FreeBSD itself. FreshPorts maintains a constant list of current ports and lists the recent additions or updates almost in realtime, and have a feed that will keep you updated. The FreeBSD ports page is mainly a search interface to the ports, as well as some documentation on ports. The FreeBSD Handbook (in Chapter 4) gives an account of how to use and comprehend ports, but a fuller picture may be had be reading the other articles listed here (at least until portsnap is introduced into the Handbook).