Keeping your FreeBSD install up-to-date

Until very recently, I thought FreeBSD lacked the ability to upgrade binary packages, the same way as the debian repository. I was wrong of course, a friend of mine told me to use pkg_upgrade that comes with bsdadminscripts.

I’ll show you how to upgrade not only packages but also the system, and keeping it up to date.
The tools I’ll use are already installed, else I’ll go through the installation.

Ports

If you aren’t familiar with ports, I’d suggest you do so. Though I’ll make a very short description of it here.
Ports contains information of where source code can be found, dependencies and BSD patches if needed.
to install a port simply go to it’s directory and enter
# make install clean

i.e. we’ll need bsdadminscripts later
# cd /usr/ports/sysutils/bsdadminscripts && make install clean

To keep ports up to date there are a couple of methods, like cvsup, manual download and portsnap, there probably are a few more, but we’ll be focusing on portsnap.

If you make a fresh install, I can recommend not to install ports, but wait till later, I’ll tell you why in a few.

If you don’t have ports installed, and you need a fresh ports tree:
# portsnap fetch extract
This will download the latest database and extract it to it’s default location; /usr/ports

using portsnap

To update your already installed ports, you can run
# portsnap fetch update

this will download the diff from your existing ports tree and the newest, and merge them in your local ports tree.
Now, if you haven’t done so in a long time, or if you are updating your tree that was installed from the CD/DVD it can take a very long time, the download itself doesn’t take that long, depending on your connection of course, the most recent ports tree in copressed format is around 60-65mb in size. What takes a long time is the extraction of alot of small files. So as I said ealier, it’s better not to install ports from the installation media and just start with a fresh download after installation.

Compiled from ports

If you have an application compiled from ports and want to update it, make sure your ports tree is up to date before continuing.

using portmaster

Install portmaster by doing pkg_add -r portmaster

as an example I’ll upgrade sit which is a nice web based incident tracker, assuming the requirements for this package has been met on a previous install, all you need to do is.
# portmaster www/sit

This will fetch the new version, compile it if required, deinstall the old package and install the new version. Since this is a web app it might require to update the database schema, this is described on the packages homepage.

to recompile all packages installed
# portmaster -a

Will do that for you, it runs through all the packages and prompt you for config settings if required, before compiling the first package, this way you don’t need to accept configs all the time through the upgrade, as you normally would do with portupgrade.

Packages

You might know about the package system now, precompiled binary packages, ready to download and install.
# pkg_add -r bash

Using -r will download the package from one of the mirrors available, rather than take the input as a file located on the local harddrive.
Unless you actively do anything, you’ll always download the release packages, after some time these can get old, bugs and security issues found etc, so it’s recommended you upgrade these to the newest release.

Since I’m using C-Shell for my root user, I’ll modify /root/.cshrc, I’ll add the link to where the stable (newest) repository is stored.

So edit your /root/.cshrc with your favorite editor, and add:
setenv PACKAGESITE ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8-stable/Latest/

Preferably with the rest setenv lines.
If you use another major version make sure you change the 8 to the major version you use. also change i386 to amd64 if you are running 64bit, or other supported architectures.

A full list of mirrors can be found here so pick on closest to you : http://www.freebsd.org/doc/handbook/mirrors-ftp.html

If you have problems using the FTP protocol, try using HTTP instead.

Save your .cshrc file, and reload it
# source ~/.cshrc

Installing a package as root now, will get the latest binary.

To uprade using the latest binaries you’ll need bsdadminscripts which can be found in ports in
/usr/ports/sysutils/bsdadminscripts (cd to the dir and type in “make install clean”)
or use pkg_add
pkg_add -r bsdadminscripts

This will give you some nice tools, amongst pkg_upgrade which we are going to use in a few.

Upgrading an application with latest precompiled package we can now use
pkg_upgrade mc

This will upgrade midnight commander, a norton commander clone, to latest binary, using the precompiled packages leaves out custom installs, so make not of that if you’ve previously compiled a package, i.e. apache with mod_dav.

pkg_upgrade -nav
This will give a list of all (-a) packages, not (-n) upgrading it, with verbose (-v) information.
removing the -n will upgrade all packages while giving you a nice verbose output on screen.

System

Updating your system is pretty easy to do, again FreeBSD delivers some nice tools out of the box to help you.

Using freebsd-update

freebsd-update fetch install
This will update your current version with latest patches.

If you want to upgrade from an old version i.e. 7.4 to 8.2 (which at current time of writing is the latest version).
freebsd-update -r 8.2-RELEASE upgrade

This will upgrade with binaries to the chosen version with latest patches. Though you might need to answer some questions about config files, for example if you edited /etc/hosts and others too. It’s usually not a big problem and you probably know what to do if you have an advanced setup.

When upgrading, it installs the kernel first, later it’ll need world, so it prompts you to reboot after the first step, and asks you to run freebsd-update install after a successful reboot.

Read the man pages for more info, when you run freebsd-update and portsnap without parameters you’ll get a small output of what you can do, if you ever are in doubt.

I suggest you try this first before doing it in a production environment. Don’t blame me if your system crashes or otherwise gives you problems, thats what the manual is for.

Good luck and happy updating.

Credits to Uffe Jakobsen

Leave a Reply

Your email address will not be published. Required fields are marked *