Updating a FreeBSD system

Update 2024-02-24: Starting with FreeBSD 14, I have used gitup:

Make sure you use a shell from the base operating system:
$ chsh -s /bin/sh root

Make sure /etc/nsswitch.conf refers to shared libraries from the base os only, e.g. do not use libnss_winbind.so from the ports during the update:
$ vi /etc/nsswitch.conf

Now upgrade FreeBSD. It'll tell you which base packages will be upgraded, and you'll be asked to merge some config files:
$ freebsd-update -r 14.0-RELEASE upgrade

Install and boot the new kernel, then install most of the new userland:
$ freebsd-update install
$ shutdown -r now
$ freebsd-update install

Install gitup and portmaster:
$ make -C /usr/port/net/gitup install clean
$ cp -aiv /usr/local/etc/gitup.conf.sample /usr/local/etc/gitup.conf
$ gitup ports
$ make -C /usr/port/ports-mgmt/portmaster install clean

Update installed software. You'll have some coffee now, but don't go away immediately as some ports may show a dialog with some options to choose from:
$ portmaster -af

Install any remainders from the base OS upgrade:
$ freebsd-update install

Now, either restart any running service, or simply reboot to let each tool and daemon make use of the new userland:
$ shutdown -r now

Optionally, you may want to free some diskspace:
$ pkg autoremove
$ pkg clean
$ rm -rv /boot/*.old /usr/ports/distfiles/*

Update 2016-05-08: Recently, I have been using a simpler and safer way to update FreeBSD boxes:

$ make -C /usr/port/ports-mgmt/portmaster install clean
$ portsnap fetch update
(Make sure you use a shell from the base operating system)
$ chsh -s /bin/csh root
(Make sure /etc/nsswitch.conf refers to shared libraries from the base os only, e.g. do not use libnss_winbind.so from the ports during the update)
$ vi /etc/nsswitch.conf
$ freebsd-update -r 10.3-RELEASE upgrade
(It'll tell you which base packages will be upgraded, and you'll be asked to merge some config files)
$ freebsd-update install
$ shutdown -r now
$ freebsd-update install
$ portmaster -af
(You'll have some coffee now, but don't go away as some ports may show a dialog with some options to choose from)
$ freebsd-update install
(Optionally, you may want to free some diskspace)
$ rm -rv /boot/*.old /usr/ports/distfiles/*

I updated this webserver from 9.0 to 9.2 running these commands as root (or run every command via sudo):

$ make -C /usr/ports/ports-mgmt/portupgrade install clean
$ freebsd-update -r 9.2-RELEASE upgrade
(It'll tell you which base packages will be upgraded)
$ freebsd-update install
(You'll be asked to merge some config files)
$ shutdown -r now
$ freebsd-update install
$ portupgrade -f ruby
$ portupgrade -f 'ruby*-bdb*'
$ rm /var/db/pkg/pkgdb.db /usr/ports/INDEX-*.db
$ pwd_mkdb -p /etc/master.passwd
$ portupgrade -af
(You'll have some coffee now, but don't go away as some ports may show a dialog with some options to choose from)
$ freebsd-update install

Finally, either reboot the machine or (re-)start enabled services in /usr/local/etc/rc.d/ manually.