[icon type=”openbsd”]Just like FreeBSD, OpenBSD comes with pkg_add command. It is used to install a binary or upgrade packages from HTTP or FTP mirror over the internet. If you have purchased OpenBSD DVD/CD, you can install packages using CD itself. The pkg_add command used to update existing packages too.
Task: Add package from ftp or http mirror
Use closest OpenBSD mirror site such as follows:
Please note that version number set to 6.0 and machine architecture is configured to amd64. You can find complete OpenBSD mirror list here.
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/
# export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.0/packages/$(machine -a)/
A note about /etc/pkg.conf file
If you are using OpenBSD v4.8+, edit/create a config file called /etc/pkg.conf. This is a recommended way of configuring on latest OpenBSD version:
# vi /etc/pkg.conf
Append/edit as follows:
installpath = http://mirror.esc7.net/pub/OpenBSD/%c/packages/%a/
Save and close the file. Where,
- installpath : URL to package repository. %c and %a will expand to OS version and package architecture at run time.
Taks: Installing links package
Type the following command:
$ sudo pkg_add -v links
$ doas pkg_add links
# pkg_add -v -i links
- -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
quirks-2.241 signed on 2016-07-26T16:56:10Z bash-4.3.46:libiconv-1.14p3: ok bash-4.3.46:gettext-0.19.7: ok bash-4.3.46: ok
Here is another example with the -i option:
# pkg_add lighttpd
quirks-2.241 signed on 2016-07-26T16:56:10Z Ambiguous: choose package for lighttpd a 0: <None> 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.
Task: Display or list of OpenBSD installed packages
Use pkg_info command:
Task: Update existing package
To upgrade or update links package type command:
# pkg_add -u links
Task: Update all packages
pkg_add will update all installed packages if no package name is provided:
# pkg_add -u
Task: Search 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
Port: php-gd-7.0.8p0 Path: lang/php/7.0,-gd Info: image manipulation extensions for php5 Maint: Robert Nagy <[email protected]> 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.8:lang/php/7.0 Archs: any
$ make search key=php-mysqli-7
Task: Delete a package
To delete a package, enter:
# pkg_delete pkgNameHere
# pkg_delete bash
bash-4.3.46: ok Read shared items: ok
Task: 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