In this guide, we will learn how to manage packages and services in FreeBSD, OpenBSD, and NetBSD, all UNIX-like operating systems. In the introduction, I will briefly give a few features of each and then show you how to manage packages and services using examples. More information about each is well documented in existing documentation. The guide is lengthy but very informative.
A brief on FreeBSD
FreeBSD is an open-source Unix-like operating system for x86, ARM, AArch64, RISC-V, POWER, and PowerPC computers. It supports features such as preemptive multitasking, memory protection, virtual memory, SMP support, all open-source development tools for different languages and frameworks, and desktop features centered around X-Windows systems such as KDE or GNOME. FreeBSD is based on the 4.4BSD-Lite release from the Computer Systems Research Group (CSRG). FreeBSD uses pkg for package management.
FreeBSD Strengths
FreeBSD’s strengths are outlined below.
- FreeBSD has a liberal open-source license. You are free to modify and distribute its source code.
- FreeBSD has strong TCP/IP networking. It implements the industry standard protocols for both servers and routing/firewall purposes.
- Fully integrated OpenZFS support e.g. support for jails, FreeBSD-specific documentation, fault management, administrative delegation, ZFS Boot Environments, etc.
- Extensive security features include a mandatory access control framework.
- It supports thousands of prebuilt packages for all supported architectures and the Ports Collection for easy customization.
- maintains rich documentation that is regularly updated. Man pages are also available for easier reference.
- FreeBSD has a simple and consistent repository structure and build system. FreeBSD uses a single repository for all its components, both kernel and userspace.
- FreeBSD is Binary compatible with Linux
Use cases
FreeBSD has lots of uses. Some of these uses are:
- Internet services: Due to its robust TCP/IP networking capabilities, FreeBSD has use cases in web servers, IPv4 and IPv6 routing, FTP servers, email servers, storage servers, virtualization servers, firewalls and NAT (“IP masquerading”) gateways, and many more.
- Education: Ideal for Computer Science and Engineering students
- Research: Being open-source, it makes an excellent system for learning operating systems and other computer science disciplines.
- Networking: it’s ideal for routers, DNS servers, firewalls, etc. configuration.
- Embedded: FreeBSD is an excellent platform for building embedded systems.
- Desktop: makes use of the X11 server and Wayland display server. The user can choose between KDE or GNOME as his preferred desktop environment.
- Software development: FreeBSD comes preinstalled with a full suite of development tools, including a full C/C++ compiler and debugger suite. Support for many other languages is also available through the ports and package collections.
Read more on FreeBSD Documentation
A brief on OpenBSD
OpenBSD is a free, multi-platform 4.4BSD-based UNIX-like operating system. Its efforts are concentrated on portability, standardization, correctness, security, and integrated cryptography. OpenBSD is freely available. The projects goal can be read at the link. OPenBSD is currently developed by volunteers and maintained by the OPenBSD Foundation. Some of the most successful projects by OpenBSD are OpenSSH, OpenBGPD, OpenNTPD, OpenSMTPD, and others.
OpenBSD supports many platforms: AMD64-based systems, 64-bit ARM systems, Intel i386 architecture and compatible processors, Apple New World PowerPC-based machines, and so on.
pkg_mgris a user-friendly graphical tool that allows you to manage installed packages, browse available packages by categories, and finally install, uninstall, or update packages. We will see this in action in the section below.
Read more on the OpenBSD website.
A brief on NetBSD
NetBSD is a free and open-source UNIX-like operating system developed by an international community and released in 1993. It was initially derived from 4.4BSD Lite2 from the University of California, Berkeley. NetBSD is distributed as a set of fully reproducible binaries, i.e., Releases, NetBSD-stable, and NetBSD-current. NetBSD is a derivative of 4.4BSD and 386BSD.
pkgsrc is a framework for managing third-party software. It is the default package manager of NetBSD.
NetBSD Features
Several features make NetBSD a good pick. These features include but are not limited to, the following:
- Security and memory hardening features: File integrity protection is provided by Veriexec, and SecureLevels has its native firewall called NPF.
- NetBSD has a powerful package management system called pkgsrc which has a release schedule of quarterly stable branches and a “rolling release” branch, which can be combined in any way with the NetBSD base system. pkgin is a binary package manager for pkgsrc that is more user-friendly. pkgsrc offers more flexibility and control.
- Supports modern storage technologies, e.g., ZFS filesystems, RAIDframe software, RAID systems, and cgd disk encryption. It also supports Logical Volume Manager as well as the BSD filesystem (with logging extension) and disklabel system.
- ARM hardware supports a wide range of open, low-cost, and high-end devices.
- Virtualization support includes Xen and the NVMM hypervisor, which securely provides hardware acceleration for QEMU.
- Support for modern x86 hardware, including NVMe, UEFI, accelerated graphics, and a range of laptops.
- Continuing stable support for a wide range of “legacy” hardware and ABIs
For project goals and the people who maintain this project, please check the provided link about NetBSD
Manage Packages and Services in FreeBSD, OpenBSD / NetBSD
Let’s do some exciting things. The guide assumes you have freshly installed FreeBSD, OpenBSD, and NetBSD servers. We will learn how to install packages, update the system, remove packages, and so on.
1. Manage Packages and Services in FreeBSD
FreeBSD provides two complementary technologies for installing third-party software: FreeBSD Ports Collection for installing packages from source and packages for installing prebuilt binaries. FreeBSD port collection is a collection of files designed to automate the process of compiling an application from the source code. This file collection has all the necessary information required to automatically download, extract, patch, compile, and install the application. Over 36,000 applications have been ported to FreeBSD and are made available for download as pre-compiled packages.
On the other hand, packages can be manipulated with the FreeBSD package management commands. Packages are manipulated using the pkg package manager.pkg provides an interface for manipulating packages: registering, adding, removing, and upgrading packages. Both ports and packages understand dependencies. If there is a missing library during an application installation, this library will be automatically installed before the application is installed.
Using pkg for Binary Package Management
Let’s briefly look at the pkg binary package manager.
Begin by checking the pkg version installed:
$ pkg -v
1.20.8
Update your system:
sudo pkg update && sudo pkg upgrade -y
To list command-line aliases:
pkg alias
To clean old packages from the cache:
sudo pkg clean -a
To search for a package:
$ pkg search nginx
modsecurity3-nginx-1.0.3 Instruction detection and prevention engine / nginx Wrapper
nginx-1.24.0_12,3 Robust and small WWW server
nginx-devel-1.25.2_7 Robust and small WWW server
nginx-lite-1.24.0,3 Robust and small WWW server (lite package)
nginx-naxsi-1.24.0,3 Robust and small WWW server (plus NAXSI)
To install packages from remote package repositories and local archives
$ sudo pkg install nginx
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 1 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
nginx: 1.24.0_12,3
Number of packages to be installed: 1
The process will require 1 MiB more space.
463 KiB to be downloaded.
Proceed with this action? [y/N]: y
Display information about installed packages:
$ pkg info nginx
nginx-1.24.0_12,3
Name : nginx
Version : 1.24.0_12,3
Installed on : Thu Oct 26 16:01:16 2023 EAT
Origin : www/nginx
Architecture : FreeBSD:13:amd64
Prefix : /usr/local
Categories : www
Licenses : BSD2CLAUSE
Maintainer : [email protected]
WWW : https://nginx.com/
Comment : Robust and small WWW server
To delete packages from the database and the system:
sudo pkg remove nginx
To audit a package:
$ pkg audit -F nginx
vulnxml file up-to-date
nginx is vulnerable:
Affected versions:
>= 1.6.0,2 : < 1.6.1,2
nginx -- inject commands into SSL session vulnerability
CVE: CVE-2014-3556
WWW: https://vuxml.FreeBSD.org/freebsd/ad747a01-1fee-11e4-8ff1-f0def16c5c1b.html
Affected versions:
>= 0.6.0 : < 1.6.2,2
nginx -- inject commands into SSL session vulnerability
CVE: CVE-2014-3616
WWW: https://vuxml.FreeBSD.org/freebsd/77b784bb-3dc6-11e4-b191-f0def16c5c1b.html
To automatically remove unused packages when you remove a package:
sudo pkg autoremove
For pkg cheatsheet:
$ pkg help
Commands supported:
add Compatibility interface to install a package
alias List the command line aliases
annotate Add, modify or delete tag-value style annotations on packages
audit Reports vulnerable packages
autoremove Removes orphan packages
check Checks for missing dependencies and database consistency
clean Cleans old packages from the cache
config Display the value of the configuration options
create Creates software package distributions
delete Deletes packages from the database and the system
fetch Fetches packages from a remote repository
help Displays help information
info Displays information about installed packages
install Installs packages from remote package repositories and local archives
lock Locks package against modifications or deletion
plugins Manages plugins and displays information about plugins
query Queries information about installed packages
register Registers a package into the local database
remove Deletes packages from the database and the system
repo Creates a package repository catalogue
rquery Queries information in repository catalogues
search Performs a search of package repository catalogues
set Modifies information about packages in the local database
ssh Package server (to be used via ssh)
shell Opens a debug shell
shlib Displays which packages link against a specific shared library
stats Displays package database statistics
triggers Execute deferred triggers
unlock Unlocks a package, allowing modification or deletion
update Updates package repository catalogues
updating Displays UPDATING information for a package
upgrade Performs upgrades of packaged software distributions
version Displays the versions of installed packages
which Displays which package installed a specific file
Using the Ports Collection
The Ports Collection is a set of makefiles, patches, and description files used to compile and install an individual application on FreeBSD. By default, Port Collection is stored in /usr/ports/.
Disclaimer: use of Ports Collection in conjunction with the binary packages provided via pkg to install software is not advisable. If the Ports Collection and pkg must be used in conjunction, then be sure that your Ports Collection and pkg are on the same branch release of the ports tree. If they are not on the same branches, there will be conflicts between dependencies installed by pkg and those from the Ports Collection.
Ports Collection contains directories for software categories. Within each software category are sub-directories for individual applications. Each application sub-directory contains a set of files that tells FreeBSD how to compile and install that program called ports skeleton. Each port skeleton includes the following files and directories: Makefile which contains statements to specify how an application is to be compiled and where its components are to be installed. distinfo which contains names and checksums of files to be downloaded to build the port. files/: which contains patches needed by the program to compile and install on FreeBSD. pkg-descr: has a more detailed description of the program and pkg-plist: which shows a list of all the files that will be installed by the port.
Installing the Ports Collection
Before compiling an application using a port, the Ports Collection must first be installed. This can be installed using the Git method.
Install Git on FreeBSD.
Navigate to /usr/ports/devel/git then run the command:
cd /usr/ports/devel/git
sudo make install clean
Follow the prompts to install git in FreeBSD if it was not already installed during FreeBSD installation.
Git could also be installed via the pkg package manager.
sudo pkg install git
To compile and install the port navigate to /usr/ports/sysutils/lsof and as a privileged user, issue the command below.
cd /usr/ports/sysutils/lsof
sudo make install
As this command runs, a working subdirectory is created which contains all the temporary files used during compilation. It’s ideal to remove this directory to save space on your disk. Execute the command:
$ sudo make install clean
===> Cleaning for lsof-4.97.0,8
The command above successfully installs the port.
Removing Installed Ports
If you wish to uninstall a port, issue the command:
sudo pkg delete <pkg-name>
Alternatively, you can use the make deinstall command as demonstrated below.
$ cd /usr/ports/sysutils/lsof
$ sudo make deinstall
===> Deinstalling for lsof
===> Deinstalling lsof-4.97.0,8
Checking integrity... done (0 conflicting)
Deinstallation has been requested for the following 1 packages (of 0 packages in the universe):
Installed packages to be REMOVED:
lsof: 4.97.0,8
Number of packages to be removed: 1
[1/1] Deinstalling lsof-4.97.0,8...
[1/1] Deleting files for lsof-4.97.0,8: 100%
Upgrading Ports
Newer versions of software become available in the Ports Collection over time. To determine if newer versions of software are available, ensure the latest version of the ports tree is installed. To list outdated installed ports, issue the command.
$ pkg version -l "<"
libedit-3.1.20221030,1 <
p5-CGI-4.57 <
py39-platformdirs-3.10.0 <
vim-9.0.1968 <
Tools exist to upgrade ports. These are Portmaster and Portupgrade.
Upgrading Ports Using Portmaster
Portmaster uses ports-mgmt/portmaster utility for upgrading installed ports. It can be installed by running the command:
cd /usr/ports/ports-mgmt/portmaster/
sudo make install clean
Portmaster defines four categories of ports: Root port has no dependencies and is not a dependency of any other ports, Trunk port has no dependencies, but other ports depend upon it, Branch port has dependencies and other ports depend upon it and Leaf port has dependencies but no other ports depend upon it.
To list these categories and search for updates:
$ portmaster -L
===>>> Root ports (No dependencies, not depended on)
===>>> dialog4ports-0.1.6_1
===>>> libatomic_ops-7.8.0
===>>> pkg-1.20.8
===>>> pkgconf-2.0.3,1
===>>> portmaster-3.27
===>>> 5 root ports
===>>> Trunk ports (No dependencies, are depended on)
===>>> autoconf-switch-20220527
===>>> boehm-gc-8.2.4
===>>> cyrus-sasl-2.1.28
===>>> db18-18.1.40
===>>> expat-2.5.0
===>>> indexinfo-0.3.1
===>>> jansson-2.14
===>>> Branch ports (Have dependencies, are depended on)
===>>> apr-1.7.3.1.6.3_1
===>>> autoconf-2.71
===>>> bash-5.2.15
===>>> curl-8.4.0
===>>> docbook-1.5
===>>> docbook-sgml-4.5_1
===>>> docbook-xml-5.0_3
===>>> docbook-xsl-1.79.1_1,1
===>>> gdbm-1.23
===>>> Leaf ports (Have dependencies, not depended on)
===>>> apache24-2.4.58
===>>> automake-1.16.5
===>>> gettext-tools-0.22
===>>> git-2.42.0
===>>> gmake-4.3_2
===>>> help2man-1.49.3
===>>> mysql57-server-5.7.42
===>>> nginx-1.24.0_12,3
===>>> New version available: vim-9.0.1994
===>>> wget-1.21.4
===>>> xmlto-0.0.28
===>>> 16 leaf ports
===>>> 107 total installed ports
===>>> 4 have new versions available
To upgrade all outdated ports, issue the command:
$ sudo portmaster -af
===>>> All >> (21)
===>>> The following actions will be taken if you choose to proceed:
Upgrade libedit-3.1.20221030,1 to libedit-3.1.20230828,1
Upgrade p5-CGI-4.57 to p5-CGI-4.59
Upgrade py39-platformdirs-3.10.0 to py39-platformdirs-3.11.0
Install devel/py-build@py39
Install devel/py-flit-core@py39
Install devel/py-installer@py39
Install devel/py-packaging@py39
Install devel/py-pyproject_hooks@py39
Install textproc/py-tomli@py39
Install devel/py-hatch-vcs@py39
Install devel/py-hatchling@py39
Install devel/py-editables@py39
Install devel/py-pathspec@py39
Install devel/py-pluggy@py39
Install devel/py-setuptools@py39
Install devel/py-setuptools_scm@py39
Install devel/py-wheel@py39
Install devel/py-trove-classifiers@py39
Install devel/py-calver@py39
Upgrade vim-9.0.1968 to vim-9.0.1994
Install sysutils/xxd
===>>> Proceed? y/n [y] y
Once the installation is complete, a summary of what has been done is listed:
===>>> The following actions were performed:
Upgrade of libedit-3.1.20221030,1 to libedit-3.1.20230828,1
Upgrade of p5-CGI-4.57 to p5-CGI-4.59
Installation of devel/py-flit-core@py39 (py39-flit-core-3.9.0)
Installation of devel/py-installer@py39 (py39-installer-0.7.0)
Installation of devel/py-packaging@py39 (py39-packaging-23.2)
Installation of textproc/py-tomli@py39 (py39-tomli-2.0.1_2)
Installation of devel/py-pyproject_hooks@py39 (py39-pyproject_hooks-1.0.0_2)
Installation of devel/py-build@py39 (py39-build-0.10.0_2)
Installation of devel/py-editables@py39 (py39-editables-0.5)
Installation of devel/py-pathspec@py39 (py39-pathspec-0.11.2)
Installation of devel/py-setuptools@py39 (py39-setuptools-63.1.0_1)
Installation of devel/py-setuptools_scm@py39 (py39-setuptools_scm-6.4.2)
Installation of devel/py-wheel@py39 (py39-wheel-0.41.2)
Installation of devel/py-pluggy@py39 (py39-pluggy-1.3.0)
Installation of devel/py-calver@py39 (py39-calver-2022.6.26_1)
Installation of devel/py-trove-classifiers@py39 (py39-trove-classifiers-2023.9.19)
Installation of devel/py-hatchling@py39 (py39-hatchling-1.18.0)
Installation of devel/py-hatch-vcs@py39 (py39-hatch-vcs-0.3.0_2)
Upgrade of py39-platformdirs-3.10.0 to py39-platformdirs-3.11.0
Installation of sysutils/xxd (xxd-9.0.1994)
Upgrade of vim-9.0.1968 to vim-9.0.1994
Portmaster could also be used to install new ports on the system, upgrading all dependencies before building and installing the new port. To use this function you need to specify the location of the ports in the ports collection.
$ sudo portmaster shells/bash
===>>> Gathering dependency list for devel/bison from ports
===>>> Initial dependency check complete for devel/bison
===>>> Continuing initial dependency check for shells/bash
===>>> Initial dependency check complete for shells/bash
===>>> bash-5.2.15 >> (1)
===>>> The following actions will be taken if you choose to proceed:
Re-install bash-5.2.15
Install devel/bison
===>>> Proceed? y/n [y] y
Upgrading Ports Using Portupgrade
Another utility for upgrading Ports is the ports-mgmt/portupgrade. It is dependent upon Ruby. To install the port, issue the command below.
cd /usr/ports/ports-mgmt/portupgrade
sudo make install clean
It is advisable to scan the list of installed ports using pkgdb -F and to fix all the inconsistencies reported before using the utility.
To upgrade all the outdated ports installed on the system, issue the command:
sudo portupgrade -ai
To upgrade only a specified application instead of all available ports, run the command:
sudo portupgrade -R <pkg_name>
To read more on ports and port collection, please check the FreeBSD Documentation.
Service management on FreeBSD
I will briefly show you how to manage services in FreeBSD. For demonstration purposes, I will start, stop, and restart the Nginx web server already installed in FreeBSD.
To start the Nginx Web Server service in FreeBSD:
Set nginx_enable to YES in /etc/rc.conf file.
sudo vim /etc/rc.conf
##add the nginx param##
nginx_enable="YES"
Then issue the command:
$ sudo /usr/local/etc/rc.d/nginx start
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
Alternatively :
$ service nginx start
nginx already running? (pid=42243).
To stop Nginx Web Server Service in FreeBSD:
$ sudo /usr/local/etc/rc.d/nginx stop
Stopping nginx.
Waiting for PIDS: 42243.
Alternatively:
service nginx stop
To restart the Nginx Web Server service in FreeBSD:
$ sudo /usr/local/etc/rc.d/nginx restart
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
nginx not running? (check /var/run/nginx.pid).
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
Alternatively:
sudo service nginx restart
Test the Nginx config file for errors:
$ sudo nginx -c /usr/local/etc/nginx/nginx.conf -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
2. Manage Packages and Services in NetBSD
NetBSD uses the pkgsrc framework for managing the installation of third-party software. pkgsrc can be used in two ways:
- Installing the package tools and using the binary packages that someone else has prepared This is the “pkg” in pkgsrc.
- Installing the “src” of pkgsrc Thus, you can build your packages, and you can still use binary packages from someone else.
For this guide, I will cover the simplest and most common method, i.e., using pkg.
Installing binary packages with pkgin
The NetBSD Project provides pre-built binaries for thousands of software packages. The recommended method for installing the software packages is via pkgin. By default, third-party software from pkgsrc is installed in the directory /usr/pkg/.
If pkgin was not installed during the NetBSD installation process, you can install it with the following command:
sudo pkg_add pkgin
To update your packages, run the command:
sudo pkgin update && pkgin upgrade -y
To search for an installed package:
pkgin search <pkg_name>
To install a package:
pkgin install <pkg_name>
I will demonstrate this by installing the Nginx web server.
$ sudo pkgin install nginx
Password:
calculating dependencies...done.
1 package to install:
nginx-1.24.0nb7
0 to refresh, 0 to upgrade, 1 to install
372K to download, 1056K to install
proceed ? [Y/n] y
## Search installed nginx package##
$ pkgin search nginx
libnjs-0.7.12 NGINX JavaScript static library
lua-resty-core-0.1.26 FFI-based Lua API for nginx modules
nginx-1.24.0nb7 = Lightweight HTTP server and mail proxy server
nginx-devel-1.25.1 Lightweight HTTP server and mail proxy server
njs-0.7.12nb1 NGINX JavaScript command line utility
To list installed packages:
$ pkgin list
nginx-1.24.0nb7 Lightweight HTTP server and mail proxy server
pcre2-10.42 Perl Compatible Regular Expressions library (major version 2)
pkg_install-20211115 Package management and administration tools for pkgsrc
pkgin-22.10.0nb2 Apt / yum like tool for managing pkgsrc binary packages
sudo-1.9.13p3 Allow others to run commands as root
vim-9.0.1598 Vim editor (vi clone) without GUI
vim-share-9.0.1598 Data files for the vim editor (vi clone)
To get a list of all commands you can run using pkgin, issue the command:
$ pkgin help
Commands and shortcuts:
list (ls ) - List installed local packages
avail (av ) - List all available remote packages
search (se ) - Search for a remote package
install (in ) - Install or upgrade packages
update (up ) - Refresh local and remote package lists
upgrade (ug ) - Upgrade all packages
full-upgrade (fug ) - Upgrade all packages (deprecated)
remove (rm ) - Remove packages and any dependent packages
keep (ke ) - Mark packages that should be kept
unkeep (uk ) - Mark packages that can be autoremoved
export (ex ) - Display PKGPATH for all keep packages
import (im ) - Import keep package list from file
show-keep (sk ) - Display keep packages
show-no-keep (snk ) - Display autoremovable packages
autoremove (ar ) - Remove orphaned dependencies
clean (cl ) - Remove downloaded package files
show-deps (sd ) - List remote package direct dependencies
show-full-deps (sfd ) - List remote package full dependencies
show-rev-deps (srd ) - List local package reverse dependencies
provides (prov) - Show which shared libraries a package provides
requires (req ) - Show which shared libraries a package requires
show-category (sc ) - List all packages belonging to a category
show-pkg-category (spc ) - Show categories a package belongs to
show-all-categories (sac ) - List all known categories
pkg-content (pc ) - Show remote package content
pkg-descr (pd ) - Show remote package long-description
pkg-build-defs (pbd ) - Show remote package build definitions
stats (st ) - Show local and remote package statistics
To remove a package:
$ sudo pkgin remove nginx
1 packages to delete:
nginx-1.24.0nb7
proceed ? [Y/n] y
Managing system services
Managing services on NetBSD is an equally easy task. To manage system startup and services, NetBSD uses the rc(8) system. System services are stored inside /etc/rc.d and are controlled through the service(8) command.
For demonstration, I will install Apache (httpd) and look at how to manage the services.
sudo pkgin install apache
To restart the Apache service, run the command:
$ sudo /etc/rc.d/httpd onerestart
httpd not running?
Starting httpd.
Alternatively, edit the file /etc/rc.conf and enable httpd as shown below.
sudo vim /etc/rc.conf
##Enable httpd##
httpd=YES
Then restart the service.
$ sudo service httpd restart
httpd not running?
Starting httpd.
To stop the service:
$ sudo service httpd stop
Stopping httpd.
To run the httpd server on startup on port 8080, edit the file and add the following parameters:
$ sudo vim /etc/rc.conf
##Add this parameter##
httpd_flags='-I 8080'
Then restart the httpd service.
3. Manage Packages and Services in OpenBSD
Let’s briefly learn how to manage packages and services in OpenBSD. To handle the installation of third-party applications in binary format, OpenBSD utilizes pkg_add as its package manager. OpenBSD does not provide regular security updates for third-party packages outside of the “current” branch. Instead, you are advised to use packages over building an application from ports.
I have already installed sudo to allow me to run commands with escalated privileges. Then edited the sudo file to include user details.
# pkg_add sudo
#visudo
Begin by updating your system packages:
sudo pkg_add -u
To install a package:
sudo pkg_add <pkg_name>
To remove a package:
sudo pkg_delete <pkg_name>
To find installed packages:
pkg_info -Q <pkg_name>
For displaying information about packages:
pkg_info <pkg_name>
Managing services (System Daemons)
System daemons (or “services”) are started, stopped, and controlled by the rc(8) script via rc.d(8). Majority of services and daemons installed on OpenBSD are controlled on boot by variables defined in /etc/rc.conf. It is advisable not to alter the /etc/rc.conf configuration file but instead use the rcctl utility to maintain the /etc/rc.conf.local file. This makes future upgrades easier as all the changes are in the one file that isn’t touched during the upgrade.
For demonstration purposes, I will install Apache and show you how to manage the services.
sudo pkg_add php
sudo pkg_add php-apache
sudo pkg_add php-mysqli
To enable the Apache service.
sudo rcctl enable apache2
To start the Apache service:
sudo rcctl start apache2
apache2(ok)
To check the status of Apache2
rcctl check apache2
apache2(ok)
To stop the Apache2 service.
$ sudo rcctl stop apache2
apache2(ok)
Wrap up
That’s about it. One thing that we could all appreciate is the wonderful documentation maintained by FreeBSD, OpenBSD, and NetBSD. In the guide, I have given a brief introduction of each and in depth shown you how to manage packages and services in the said distros. I hope you find the guide helpful.





