so one of the really nice things about FreeBSD (yeah, i know, there seem to be a lot of really nice things about FreeBSD. that's because there's a lot of really nice things about FreeBSD.) is the ports tree.

if you've used a linux system, you probably were amused by the fact that it came with like a million little programs of every type, most of which even worked and a few of which you actually found useful. FreeBSD, it turns out, does not install nearly as much crap by default. right now, you're thinking to yourself "this will be a problem, because when i go to download my favorite program off the web, it only has a linux version, so i would have to get the source and compile it myself, and it probably won't work right under FreeBSD, so i'll have to hack at it myself to fix it, aw, this is hard, i don't want to do this anymore, i'm going back to linux."

fortunately, the brilliant people at the FreeBSD project have anticipated this problem, and solved it. when you installed FreeBSD you probably installed what is called a ports tree. this is a directory filled with other directories which are in turn filled with yet more directories. exciting, isn't it. actually, i should mention that those directories all have a cunningly designed set of makefiles in them, which will automate the process of downloading, patching, and compiling all sorts of usefull programs. if you don't want to compile them yourself, you're in luck, because they also forsaw that, and made the makefiles able to build binary packages that contain precompiled versions of the same software which you can easily download and install. with a good network connection and a single command, you can install almost anything. if you don't have a good connection, i'm sorry for you, but fortunately you can buy a release version of FreeBSD on cd and it will come with a large selection of the ports precompiled and ready to go.

first, lets see how to play with the packages, since that's easy. there are a bunch of commands for playing with them, all of which are conveniently named pkg_something where somehting is of course not something.

to install a package, assuming you have it downloaded, you type pkg_add packagename.tgz where packagename.tgz is, you guessed it, the package you downloaded. if you don't happen to have the package lying around, you can do pkg_add -r packagename (note, no .tgz this time), and it'll download the package from the FreeBSD ftp server and install it. pkg_add is smart, and if it can, it will try and find any dependencies for the package you are installing and install them too.

"but i want to know what's already installed on my system" you say... that's simple, you just use pkg_info. if you want to see if the versions you have installed are out of date compared to the new ports tree you just cvsuped to, you can use pkg_version. if you want a more helpfull and human readable version of that, you can use pkg_version -cv and it'll give you something much nicer to read. to get rid of a package, predictably, you use pkg_delete.

"but i'm paranoid and don't trust the packages on the FreeBSD ftp site..." well, then you should build the ports by hand, which is of course blindingly easy. just go to the directory of the port you want to install, (/usr/ports/something) and type make. then, once it's downloaded and compiled it, you can type make install. to get rid of the work directories and tarballs it downloaded (they can take up a lot of space) type make distclean. to later remove something you installed as a port, just go to it's directory and type make deinstall.

a neat trick, if you don't know what port you want, but want to find it, is to go to the top of the ports tree (/usr/ports) and type make search. you guessed it, it searches the ports for keywords and gives you some output telling you what ports matched. i just thought that was neat.

for more info on the ports, check out (yeah, i know, i'm sounding like a broken record) the FreeBSD handbook.