You can use portupgrade to keep ports up to date in FreeBSD. It is best to do this often to avoid as many problems as possible.
It sometimes causes a problem and you should be prepared to resolve any problems it may cause. You have been warned!
First, if you have not installed portupgrade, you can install it from packages or ports. To install it from packages, use:
pkg_add -r portupgrade
Or from ports, use:
make install distclean
Assuming you have portupgrade installed, you should first upgrade your ports collection. I have detailed how to do this in this post.
Once the ports tree is updated (it takes a while), you can check which ports/packages require upgrading with the following command:
pkg_version -v | grep -v up-to-date
This will show you 1 line per package that needs upgrading. On the left, the installed package and version – and on the right the new version.
To upgrade all ports/packages (this takes time as it will download and compile everything), use the following command:
portupgrade -rv \*
Depending on your shell, you may or may not require the escape character ( \ ) before the *.
Beware that the uninstall of some ports will shutdown daemons but the installer will not restart them. A common example is the MySQL server port. A simple solution is to reboot the server once done.
Any problems will be reported at the end of the process. As I explained above, you may need to resolve some issues manually and this can be complex!