How to change or configure OpenBSD package install mirror

Posted on in Categories , , last updated August 16, 2017

openbsd commandI am trying to install nginx server on OpenBSD but keep getting an error that read as follows when I run the pkg_add command:

https://mirror.leaseweb.com/pub/OpenBSD/6.1/packages/amd64/quirks-2.304.tgz” title=”quirks-2.304.tgz: ftp: Error retrieving file: 404 Not Found
signify: gzheader truncated
https://mirror.leaseweb.com/pub/OpenBSD/6.1/packages/amd64/nginx-1.10.2p2.tgz” title=”nginx-1.10.2p2.tgz: ftp: Error retrieving file: 404 Not Found
signify: gzheader truncated

How do I change or configure OpenBSD package install mirror for the pkg_add command?

For installing and upgrading packages set internet mirror
To install or update software packages you need to use the pkg_add command on OpenBSD Unix system. You can PKG_PATH variable pointing to the OpenBSD mirror or edit the file named installurl.

Method 1: Edit /etc/installurl

This file contains a single line specifying an OpenBSD mirror. This file is created by the installer script during installation or upgrade. To edit,
$ doas vi /etc/installurl
Delete or comment out (add # at the beginning of old mirror) existing line. Next add/append a new mirror name
#https://mirror.leaseweb.com/pub/OpenBSD
https://ftp.openbsd.org/pub/OpenBSD

Save and close the file. You can now use the pkg_add command:
$ doas pkg_add -v nginx
To update all installed packages from new mirror run:
$ doas pkg_add -u -v
Sample outputs:

Update candidates: quirks-2.304 -> quirks-2.304
quirks-2.304 signed on 2017-04-02T15:01:33Z
Update candidates: bash-4.4.12 -> bash-4.4.12
Update candidates: gettext-0.19.8.1 -> gettext-0.19.8.1
Update candidates: libiconv-1.14p3 -> libiconv-1.14p3
Update candidates: pcre-8.38p0 -> pcre-8.38p0
Update candidates: pftop-0.7p15 -> pftop-0.7p15

Method 2: Set PKG_PATH shell variable

If a given package name cannot be found, the directories named by PKG_PATH are searched. One can set it as follows for bash/sh/ksh:
# export PKG_PATH=http://ftp.eu.openbsd.org/pub/OpenBSD/`uname -r`/packages/`uname -m`/
OR
# export PKG_PATH=https://ftp4.usa.openbsd.org/pub/OpenBSD/$(uname -r)/packages/$(uname -m)/
Run the command:
# pkg_add -v packagename
# pkg_add -v nginx

Sample outputs:

Update candidates: quirks-2.304 -> quirks-2.304
quirks-2.304 signed on 2017-04-02T15:01:33Z
nginx-1.10.2p2:pcre-8.38p0: ok
nginx-1.10.2p2: ok
The following new rcscripts were installed: /etc/rc.d/nginx
See rcctl(8) for details.
Look in /usr/local/share/doc/pkg-readmes for extra documentation.
Extracted 4819702 from 4820755

For more info see the pkg_add man page:
$ man pkg_add
$ man 5 installurl

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment