Freebsd – pkg_add Environment on FreeBSD

environment-variablesfreebsdpackage-management

Suppose you want to add a package foo but when you invoke pkg_add via:

pkg_add -r foo

you get an error:

Error: Unable to get ftp://.../foo.tbz: File unavailable ...

It's not a problem since according to pkg_add's man page, all you have to do is to set the PACKAGEROOT environment variable to the root directory of foo:

PACKAGEROOT=ftp://root/to/package

Not so fast! It is a problem–it doesn't work! If you don't export PACKAGEROOT, then pkg_add uses its default location and exporting PACKAGEROOT give you the error:

pkg_add: can't stat package file 'foo'

The same holds when setting the PACKAGESITE variable.

Now, I have actually solved this problem:

pkg_add -r ftp://my/package/root/foo.tbz

works fine. Nevertheless, I have two questions:

  1. What exactly does can't stat package file 'foo' mean?
  2. Why doesn't this work as advertised?

For the interested, I experienced this problem when trying to install Enlightenment. The ports version is old and I didn't want to compile anyway since that takes a while. I set PACKAGEROOT and PACKAGESITE independently via different terminal sessions:

export PACKAGEROOT=ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/x11-wm

and

export PACKAGESITE=ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/x11-wm/

but neither worked.

Best Answer

The difference between PACKAGEROOT and PACKAGESITE is that PACKAGEROOT retains the original directory logic and PACKAGESITE does not. These are correct:

PACKAGEROOT=ftp://ftp.freebsd.org

PACKAGESITE=ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/

In answer to your questions:

  1. It means pkg_add it couldn't find the file. You're seeing it only with PACKAGESITE because setting that variable overrides the search process, which would usually yield "Couldn't find package foo."

  2. It does. When you have PACKAGESITE specified, all "pkg_add -r foo" does is try to open up $PACKAGESITE/foo.tbz. Do you see the problem? Go to your PACKAGESITE value and look for enlightenment.tbz.

    You didn't find it. The closest you found was enlightenment-0.16.999.042_3,2.tbz. So pkg_add -r "enlightenment-0.16.999.042_3,2" would work. Change your PACKAGESITE to ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/ and it'll work.

    This is the whole reason the Latest/ subdirectory exists.