Is there any way to make the simple command

sudo pkg_add some-package

work on an ordinary installation of NetBSD without recompiling anything from source code? All other Unix systems that I have tried provide an equivalent command out of the box with little effort.

The best I could think up was to add

export PKG_PATH="ftp://ftp.NetBSD.org/pub/pkgsrc/packages/$(uname)/$(uname -m)/$(uname -r)/All/"

to /root/.shrc but sudo doesn't read .shrc.

The pkgsrc FAQ, "Using 'sudo' with pkgsrc" says that you can adapt the "just-in-time su(1) feature of pkgsrc" to use sudo but it requires editing a makefile and recompiling something. That seems like a steep requirement for such a basic task. Even without this modification, pkg_add doesn't ask me to su when I try to install packages as a normal user - it just says pkg_add: Can't create pkgdb entry: /var/db/pkg/<...>: Permission denied

OpenBSD has an /etc/installurl file for this purpose but I couldn't find an equivalent one for NetBSD.

  • FWIW, in OpenBSD you can also allow doas(1) to not touch e.g. PKG_PATH and TRUSTED_PKG_PATH in the environment. – Kusalananda Apr 14 '18 at 8:03
  • I think sudo's env_keep could also be used to preserve PKG_PATH but it seems simpler and safer to have a system-wide setting in the package manager's own configuration file. – Lassi Apr 14 '18 at 8:28

The right file is /etc/pkg_install.conf. To set it up, run this as root:

echo "PKG_PATH=ftp://ftp.NetBSD.org/pub/pkgsrc/packages/$(uname)/$(uname -m)/$(uname -r)/All/" >> /etc/pkg_install.conf

See the pkg_install.conf(5) manual page for details about the file.

Note that the file has to be updated after each release upgrade. The release version number $(uname -r) will get stale.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.