FreeBSD Update and Upgrade pkg Packages With pkg Binary Package Manager

FreeBSD is a popular server platform and open-source Unix-like operating system developed from the Berkeley Software Distribution (BSD). FreeBSD is an operating system intended to run modern servers, PCs, and embedded devices. The term BSD is an abbreviation of "Berkeley Software Distribution". This refers to a source code release from the University of California, Berkeley that was originally an add-on to the AT&T Research UNIX operating system. Several open source operating system projects are based on the 4.4BSD-Lite version of this source code. In addition, they include several packages from other Open Source projects, especially the GNU project.

FreeBSD has a variety of system tools as part of its base system. FreeBSD offers two free mechanisms for installing third-party programs/applications such as NGINX, apache, unbound, hitch, freeradius, mysql-server, openldap and others. To install this application, FreeBSD offers 2 installation methods.
  • Ports: The FreeBSD Ports Collection is used to install applications from source code.
  • pkg: pkg package is used to install applications from built-in binaries.
The discussion in the article will be limited to how to install programs/applications on FreeBSD machines with the pkg package. For those who want to install programs/applications with the Ports system, you can read the previous article. Not only that, this article also discusses how to update and upgrade pkg packages.





1. pkg Binary Package Manager

pkg is a next-generation replacement for the existing FreeBSD package management utility, with several features that make working with binary packages faster and simpler. The pkg binary package is located in the /usr/local directory. Most of the configuration files are located under /usr/local/etc. If you come from the Linux community, you might find this unusual. Important files and directories for the pkg package management system in FreeBSD are listed below:

Official FreeBSD repositories location: /etc/pkg
The pkg configuration file: /usr/local/etc/pkg.conf
Package cache directory: /var/cache/pkg
FreeBSD repository file: /etc/pkg/FreeBSD.conf
Custom repositories directory: /usr/local/etc/pkg/repos
SQLite database file: /var/db/pkg/local.sqlite

To start using the pkg package, type the following script.

root@ns1:~ # pkg install autoconf automake libtool pkgconf libucl zsh
To install the latest release version of the pkg package, enter the following script in the /etc/make.conf file.

root@ns1:~ # ee /etc/make.conf
WITH_PKG=yes

2. Binary Package Configuration pkg

If WITH_PKG is yes, continue by downloading the pkg binary package.

root@ns1:~ # cd /usr/local/etc
root@ns1:/usr/local/etc #
git clone https://github.com/freebsd/pkg
Wait a few moments, if the git cloning process has finished, continue by installing the pkg package.

root@ns1:~ # cd /usr/local/etc/pkg
root@ns1:/usr/local/etc/pkg #
./configure
No installed jimsh or tclsh, building local bootstrap jimsh0
Host System...x86_64-unknown-freebsd13.2
Build System...x86_64-unknown-freebsd13.2
C compiler... cc -g -O2
C++ compiler... c++ -g -O2
Build C compiler...cc
Checking for stdlib.h...ok
Checking for git...ok
Checking for archive_read_open...ok
Checking for zlibVersion...ok
Checking for BZ2_bzReadOpen...ok
Checking for lzma_version_string...ok
Checking for SHA256_Data...ok
Checking for archive_write_add_filter_zstd...ok
Checking for ZSTD_versionNumber...ok
Checking for atomic builtins... ok
Checking for /proc/self/fd support... no
Checking for memmove...ok
Checking for usleep...ok
Checking for pread...ok
Checking for pwrite...ok
Checking for SOCK_SEQPACKET...ok
Checking for struct sockaddr_in.sin_len...ok
Checking for struct stat.st_mtim...ok
Checking for struct stat.st_flags...ok
Checking for gmtime_r...ok
Checking for isnan...ok
Checking for localtime_r...ok
Checking for __res_setservers...ok
Checking for unlinkat...ok
Checking for faccessat...ok
Checking for fstatat...ok
Checking for openat...ok
Checking for readlinkat...ok
Checking for fflagstostr...ok
Checking for reallocarray...ok
Checking for strchrnul...(cached) ok
Checking for copy_file_range...ok
Checking for humanize_number...ok
Checking for fts_open...ok
Checking for humanize_number...ok
Checking for dlclose...ok
Checking for __res_query...ok
Checking for link.h...ok
Checking for machine/endian.h...ok
Checking for osreldate.h...ok
Checking for readpassphrase.h...ok
Checking for sys/procctl.h...ok
Checking for sys/statfs.h...not found
Checking for sys/statvfs.h...ok
Checking for libutil.h...(cached) ok
Checking for dirent.h...ok
Checking for sys/sockio.h...ok
Checking for endian.h...ok
Checking for sys/endian.h...ok
Checking for be16dec...ok
Checking for be16enc...ok
Checking for be32dec...ok
Checking for be32enc...ok
Checking for be64dec...ok
Checking for be64enc...ok
Checking for le16dec...ok
Checking for le16enc...ok
Checking for le32dec...ok
Checking for le32enc...ok
Checking for le64dec...ok
Checking for le64enc...ok
Checking for elf-hints.h...ok
Checking for cap_sandboxed...ok
Checking for sys/capsicum.h...ok
Checking for pkg-config...1.8.1
Created tests/Makefile from tests/Makefile.autosetup
Created docs/Makefile from docs/Makefile.autosetup
Created external/liblua/Makefile from external/liblua/Makefile.autosetup
Created external/msgpuck/Makefile from external/msgpuck/Makefile.autosetup
Created external/yxml/Makefile from external/yxml/Makefile.autosetup
Created scripts/Makefile from scripts/Makefile.autosetup
Created external/libcurl/Makefile from external/libcurl/Makefile.autosetup
After the configure process is complete, continue by installing the pkg package.

root@ns1:/usr/local/etc/pkg # make
root@ns1:/usr/local/etc/pkg #
make install
Now that your FreeBSD machine has the pkg binary package, you can use pkg to install several third-party applications/programs. So that the pkg package can be used to install applications/programs, create a FreeBSD.conf file in the /usr/local/etc/pkg/repos folder.

root@ns1:~ # mkdir -p /usr/local/etc/pkg/repos
root@ns1:~ #
touch /usr/local/etc/pkg/repos/FreeBSD.conf
root@ns1:~ #
chmod +x /usr/local/etc/pkg/repos/FreeBSD.conf
Enter the script below in the /usr/local/etc/pkg/repos/FreeBSD.conf file.

root@ns1:~ # cd /usr/local/etc/pkg/repos
root@ns1:/usr/local/etc/pkg/repos #
ee FreeBSD.conf
FreeBSD: { enabled: yes }
Update the pkg package.

root@ns1:~ # pkg update -f
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
root@ns1:~ #
pkg upgrade -f
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking for upgrades (0 candidates): 100%
Processing candidates (0 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.
The pkg utility is not loaded by default on FreeBSD, however, you can quickly install pkg by running the following command.

root@ns1:~ # pkg bootstrap -f
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:13:amd64/latest, please wait...
Installing pkg-1.19.2...
package pkg is already installed, forced install
Extracting pkg-1.19.2: 100%

3. How to Use PKG Command

One of FreeBSD's main features is its pkg package management system, which allows users to easily install, update, and remove software packages. In this sub-article, we will discuss examples of PKG commands that are useful for managing packages in FreeBSD.

a. Install Application Programs
Below we will provide several ways to install application programs that run on FreeBSD.

root@ns1:~ # pkg install apache24
root@ns1:~ #
pkg install nginx
root@ns1:~ #
pkg install unbound
root@ns1:~ #
pkg install isc-dhcp44-server
b. Searching for Application Programs
Below we will provide several ways to search for application programs that you will install on FreeBSD.

root@ns1:~ # pkg search python
root@ns1:~ #
pkg search apache24
root@ns1:~ #
pkg search nginx
root@ns1:~ #
pkg search unbound
lua51-luaunbound-1.0.0_1 Lua binding to libunbound
lua52-luaunbound-1.0.0_1 Lua binding to libunbound
lua53-luaunbound-1.0.0_1 Lua binding to libunbound
lua54-luaunbound-1.0.0_1 Lua binding to libunbound
unbound-1.17.1_2 Validating, recursive, and caching DNS resolver
unbound_exporter-0.4.1_6 Prometheus metrics exporter for the Unbound DNS resolver
c. View application programs that have been installed

root@ns1:~ # pkg info
d. Delete application programs that have been installed

root@ns1:~ # pkg delete python
root@ns1:~ #
pkg delete apache24
root@ns1:~ #
pkg delete nginx
root@ns1:~ #
pkg delete unbound
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:
unbound: 1.17.1_2

Number of packages to be removed: 1

The operation will free 8 MiB.

Proceed with deinstalling packages? [y/N]: y
[1/1] Deinstalling unbound-1.17.1_2...
[1/1] Deleting files for unbound-1.17.1_2: 100%
You may need to manually remove /usr/local/etc/unbound/unbound.conf if it is no longer needed.
e. Displays pkg Package Information

root@ns1:~ # pkg info python
root@ns1:~ #
pkg info -d python
root@ns1:~ #
pkg info -d python
root@ns1:~ #
pkg info -d python
FreeBSD implements two companion technologies for installing third-party software. FreeBSD Ports Collection, for installing from source code, and packages, for installing from pre-built binaries. But as FreeBSD moves systems more firmly toward universal package management, you should try to manage third-party software with pkg as much as possible. Avoid using ports unless the software you want does not have a packaged version or you need to adjust compile-time options.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post