Friday, May 29, 2009

Fixing pkg_add -r on FreeBSD (things no one tells you)

On FreeBSD when you want to install a program you have to make a choice. Your two choices are to install a package or compile from ports.

Installing a package means you download a binary package and copy all the files to the right places. Everything is already compiled. This is how Windows works. When you install a piece of software it has already been compiled.

Your second option is to compile from ports. What this means is that the source files are downloaded and then compiled on your system. You need to have all the prerequisites for the compile to be successful.

Why choose one over the other? Well with packages sometimes the binary doesn't work. Either you happen to have a newer or older file than what the creator compiled it with or you changed something with your system and it doesn't match anymore with the author's compiled environment. However packages are fast to install. No need to break out gcc and compile source code.

Ports on the other hand will almost always work. They are targetted for your system because you are compiling them. It takes a bit longer but you also get to customize any of the build options.


To install a program from package you use this command:

pkg_add -r

Examples:

pkg_add -r xorg
pkg_add -r nano
pkg_add -r curl

I like pkg_add -r because it fetches the package for me and installs it. It does that by looking at your system's uname (I think) and forms a URL to FreeBSD's software repository. The problem is that after a while repositories are taken offline. So if you are using some older version of FreeBSD and trying to do a pkg_add -r it will return that it can't find the package.

The thing is, the package is probably still around but in a newer form. The newer package is compatible with your version if you can find it. FreeBSD makes a statement that says packages in the same stable branch will always be compatible.

To force pkg_add -r to bend to your will you edit the PACKAGESITE environment variable. If you want to force pkg_add -to download FreeBSD 7-STABLE packages, set PACKAGESITE to ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-7-stable/Latest/.

Be very careful though that you point to the right URL. I actually pointed to the wrong URL and downloaded 32-bit packages instead of the amd64 packages which I needed:

http://ftp2.at.freebsd.org/pub/FreeBSD/ports/amd64/packages-7-stable/Latest/

No comments: