Add package from ftp or http mirror
Always use closest OpenBSD mirror site such as follows:
ftp://ftp.openbsd.org/pub/OpenBSD/4.0/packages/i386/
https://mirror.esc7.net/pub/OpenBSD/6.2/packages/amd64/
Please note that version number set to 6.0 and machine architecture is configured to amd64. You can find complete OpenBSD mirror list here.
How to configure PKG_PATH
First, you need to setup PKG_PATH variable so that you don’t have to type complete mirror path each and every time. You need to add PKG_PATH to your shell startup file such as ~/.bashrc or ~/.bash_profile. PKG_PATH variable MUST end in a slash:
$ export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.0/packages/amd64/
OR
# export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.0/packages/$(machine -a)/
A note about /etc/installurl file
The /etc/installurl file contains a single line specifying an OpenBSD mirror server URL, such as:
https://ftp.openbsd.org/pub/OpenBSD
Edit/create a config file called /etc/installurl. This is a recommended way of configuring on latest OpenBSD version:
# vi /etc/installurl
Append/edit as follows:
https://mirror.esc7.net/pub/OpenBSD/
Save and close the file in vim/vi. Where,
How to install links package
Type the following command:
$ sudo pkg_add -v links
One can use doas which is default on OpenBSD:
$ doas pkg_add links
Another option is to become root using ‘doas’ or ‘su’ and type:
# pkg_add -v -i links
Where,
- -v : Verbose mode (display more information)
- -i : Interactive installation. It may ask you question such as which version you would like to install and so on.
You can skip the -v and -i option. For example, install bash package, enter:
# pkg_add bash
Sample output:
Here is another example with the -i option:
# pkg_add lighttpd
Sample outputs:
quirks-2.241 signed on 2016-07-26T16:56:10Z Ambiguous: choose package for lighttpd a 0: 1: lighttpd-1.4.38p1 2: lighttpd-1.4.38p1-ldap 3: lighttpd-1.4.38p1-ldap-mysql 4: lighttpd-1.4.38p1-mysql Your choice: <strong>1</strong> lighttpd-1.4.38p1:pcre-8.38p0: ok lighttpd-1.4.38p1:spawn-fcgi-1.6.3p0: ok lighttpd-1.4.38p1:lua-5.1.5p6: ok lighttpd-1.4.38p1: ok The following new rcscripts were installed: /etc/rc.d/lighttpd See rcctl(8) for details.
Note that pkg_add prompted for version of lighttpd, you wish to install.
How to display or list of OpenBSD installed packages
Use pkg_info command:
$ pkg_info
Sample outputs:
Listing installed packages
How to update existing package
Let us upgrade or update links package. Type the following pkg_add command:
# pkg_add -u links
How to update all packages on OpenBSD
pkg_add will update all installed packages if no package name is provided:
# pkg_add -u
Related: How to apply patches on OpenBSD system/kernel and packages easily
How to search for packages
Type the following commands (see how to install ports tree on OpenBSD) to search for php-gd-7 package:
$ cd /usr/ports
$ make search key=php-gd-7
Sample outputs:
Port: php-gd-7.0.23 Path: lang/php/7.0,-gd Info: image manipulation extensions for php5 Maint: Robert Nagy <robert@openbsd.org> Index: lang www L-deps: graphics/jpeg graphics/png B-deps: archivers/bzip2 devel/autoconf/2.69 devel/bison devel/metaauto www/apache-httpd R-deps: php-7.0.23:lang/php/7.0 Archs: any
Another example:
$ make search key=php-mysqli-7
How to remove/delete a package on OpenBSD
You can remove or delete a package, enter:
# pkg_delete pkgNameHere
# pkg_delete bash
Sample outputs:
bash-4.4.12p0: ok Read shared items: ok
How to set active or passive mode for ftp mirrors
If you are behind firewall you may need to set active or passive mode with FTPMODE variable (default is passive).
$ export FTPMODE=active
References:
See man pages for more info:
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 5 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Thanks for article but “pkg_add” is not working for updating all packages and it returns “pkg_add: Missing pkgname” error.
For doing so, you need to use “pkg_add -u”.
From OpenBSD manual pages:
-u Update the given installed pkgname(s), and anything it depends
upon. If no pkgname is given, pkg_add will update all installed
packages. This relies on PKG_PATH to figure out the new package
names.
Best regards
export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/5.0/packages/i386
I have do that, I want to install unzip, but I can’t. Sorry I’m Indonesian and very very newbie in UNIX.
very very useful!
thanks for sharing 🙂
jman – I prefer to use the packages whenever possible — both pkg_add(1) and the ports methods are capable of determining required dependencies. If you are experiencing specific package dependency issues, I suggest posting on the appropriate OpenBSD mail list.
Those OpenBSD gurus are super-smart and very helpful.
Are packages better than ports?
With ports I do – make install clean and it usually sorts out any dependency issues.
But with pkg_add I have had dependency errors.