Get more up-to-date packages
This is a quick tip for saving some compile time and using binary packages instead, where possible.* This assumes that you've updated your ports tree (using cvsup or portsnap) from what it was at installation or the latest upgrade/release. One might choose to not update the ports tree and to just leave your ports tree as it was at installation (or at the last release your system has achieved). I call this the lazy method and it works great (as long as you can be just as happy with version 1.8.10 of some port as you would be with version 1.9.4). But, if you're going lazy, then this tip is not for you and -- in fact -- has the potential to cause inconsistencies which defeat the purpose of the lazy method.
If you do update your ports tree then you might be dismayed that now you have to compile everything. But, you don't. "pkg_add" checks for an environment variable called PACKAGESITE which tells it exactly where to look for new packages -- instead of the default which will look for release packages. Change that and now you can get a more recent version. At present, on FreeBSD version 6.x, this is the value that works for me:
PACKAGESITE='ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-stable/Latest/'
export PACKAGESITE
I mention version 6.x specifically because right now the "packages-stable" sub-directory above is a link to "packages-6-stable" on the ftp server. When version 7.x officially becomes the new stable branch, you can expect that link to change. Likewise, the above value wouldn't work for version 4.x (but substitute "packages-4-stable" for "packages-stable" and you'll be in business (yeah, you probably could have gotten that one yourself :) )). So, you may need to update this variable any time you change major versions or the Project moves the "stable" designation to the next major version. Another way to handle this, of course, would be to just use "packages-6-stable" in the URL in the first place -- really, that's the best way, since "packages-stable" will be relinked to a different major version at some point in the future.
While we're at it, this would be a good time to ping some of the ftp mirror sites and find out which one is closest to you. Then you could substitute the hostname in the variable above with something closer and hopefully quicker, say, 'ftp19.freebsd.org' or 'ftp4.au.freebsd.org'. (... Non-working examples. See here for list of valid candidates.)
Probably (hopefully!), you're using portupgrade or another tool to help manage your ports. With portupgrade all you have to do is add the '-P' option to any portupgrade (or portinstall) command and it will recognize the environment variable and check the above ftp address first for the correct version package, before falling back to actually compiling it from the port. ... Or, as all FreeBSD users like to say: everything just works.
Update
I got a good question on this in the comments, one that I'd wondered about myself. I didn't have a good answer so I just gave a crappy one. But, since then I've run across a better answer in the "pkg_fetch" man page. This post is getting long, so I explain here.
* Update 2
This method isn't working right now! If you're on 6.0-6.2, you'd better do all your port upgrades by compiling for now. More here.
Labels: ports