I was asked many times to write an article about pkg(8) – the current FreeBSD modern package manager sometimes also called PKGng.
In this entry I will try to describe less known pkg(8) features.
About 8 years ago – when pkg(8) did not even existed – I wrote HOWTO: keeping FreeBSD’s base system and packages up-to-date post. It was even later published in the BSD Magazine 2012/01 episode (Issue 30).
Back in 2011 keeping packages up to date was little more tricky then it is now. You was forced to use the FreeBSD’s STABLE branch for them as packages in RELEASE were never updated – like currently it is in the OpenBSD world. The packages in FreeBSD’s STABLE branch were built every 2 weeks which was enough at that time.
You could of course compile everything from FreeBSD Ports using portmaster but you will waste lots of time for compiling your life. When pkg_add/pkg_delete/pkg_info were THE package tools on FreeBSD the pkg_upgrade script from the bsdadminscripts package was quite helpful with the upgrade process. It would fetch latest available packages from the STABLE branch FTP server and update installed packages. To check for the security issues in packages another external tools called portaudit was needed.
Today we have pkg(8) with all its features along with pkg upgrade to update the installed packages. Thanks to pkg audit the third party tool portaudit is not longer needed. We even have pkg autoremove to automatically remove unneeded dependencies.
I will try not to copy information available on the already great FreeBSD Handbook described in the 4.4. Using pkg for Binary Package Management chapter.
Older FreeBSD Versions
Before FreeBSD 10.x to use new pkg(8) tools instead of the old pkg_* ones there was need to have WITH_PKGNG=yes in the /etc/make.conf file.
Currently only the only supported releases of FreeBSD are recently released 12.0 and still more stable and polished 11.2 so there is no need to put anything in the /etc/make.conf file anymore to use pkg(8) framework.
Database
The pkg(8) database (SQLite database actually) is kept in the /var/db/pkg directory.
These are the contents of the /var/db/pkg dir just after pkg(8) bootstrap process.
# find /var/db/pkg /var/db/pkg /var/db/pkg/FreeBSD.meta /var/db/pkg/vuln.xml /var/db/pkg/local.sqlite /var/db/pkg/repo-FreeBSD.sqlite
The most important file is the /var/db/pkg/local.sqlite file as this is the database of installed packages and its files. By typing pkg shell you can actually connect to this SQLite database with SQLite interpreter.
# pkg shell -- Loading resources from /home/vermaden/.sqliterc SQLite version 3.15.2 2016-11-28 19:13:37 Enter ".help" for usage hints. > .q #
If for some reason you will find that pkg(8) tools does not work or are broken you may connect to it with sqlite3 command from the sqlite3 package. Do not use the sqlite package as it holds the 2.x version of SQLite which is not forward compatible with the 3.x version used by pkg(8)
# file /var/db/pkg/* /var/db/pkg/FreeBSD.meta: ASCII text /var/db/pkg/local.sqlite: SQLite 3.x database, user version 34, last written using SQLite version 3015002 /var/db/pkg/repo-FreeBSD.sqlite: SQLite 3.x database, user version 2014, last written using SQLite version 3015002 /var/db/pkg/vuln.xml: XML 1.0 document, UTF-8 Unicode text, with very long lines # sqlite3 /var/db/pkg/local.sqlite -- Loading resources from /home/vermaden/.sqliterc SQLite version 3.26.0 2018-12-01 12:34:55 Enter ".help" for usage hints. > .q #
Lock/Unlock
With pkg(8) specified packages can now be locked with pkg lock command. This means that the pkg upgrade or even pkg delete operations (or pkg autoremove) would not touch them. You can list locked packages with -l options as shown below.
# pkg lock -l Currently locked packages: conky-1.9.0_6 exfat-utils-1.2.8 ffmpeg-4.1_1,1 fusefs-exfat-1.2.8 lame-3.100_2 # pkg delete exfat-utils Checking integrity... done (0 conflicting) The following package(s) are locked and may not be removed: exfat-utils 1 packages requested for removal: 1 locked, 0 missing #
As you can see its not possible to pkg delete the locked exfat-utils package. You will first have to unlock it with pkg unlock command. You can do that interactively or not with -y option as shown below.
# pkg unlock exfat-utils exfat-utils-1.2.8: unlock this package? [y/N]: y Unlocking exfat-utils-1.2.8 # pkg lock -y exfat-utils Locking exfat-utils-1.2.8
Now, why would you lock any packages?
Based on my experience these are potential reasons to lock certain packages:
- You combine packages with ports.
- Package for the port does not exist.
- Official package has different default options then yours.
- You really want to use older version of package.
Actually I use lock/unlock mechanism because all of the above are true for me.
I combine ports and packages (practice often discouraged in the FreeBSD world) because some software I use is not available as packages – because of licensing issues. These are anything related to Microsoft exFAT filesystem (exfat-utils/fusefs-exfat) and MP3 (lame). What is more astonishing for me is that OpenBSD provides lame package since YEARS yet FreeBSD team is still scared of the patents. I also need to build custom version of ffmpeg package – just to include lame support but still custom. The last thing I keep locked is Conky. It was and still is working great in 1.9 version but its developers broke it badly in the 1.10 version (now even 1.11 is available). It was just not possible to right click with mouse on the desktop and have Openbox menu – or to name the issue – Conky did not pass mouse events to the Window Manager that ruled the desktop. So I used one of the other Ports tools, the portdowngrade to fetch last 1.9 files into my Ports tree, then compile the 1.9 conky package and lock it for good.
You probably already know that I prefer to run dzen2 for screen information but I use conky rarely for my ‘FreeBSD Dashboard’ with all needed information that I enable only when I need it – with [Scroll Lock] key.
For the record – here is how it looks.
Provides
If you also happen to be RHEL/Fedora (or just yum/rpm) user you probably missed the ‘provides’ feature on FreeBSD pkg(8) package manager. Why it is so useful? Because with ‘provides’ database you can install packages by specifying the exact binary or file name of the package. For example You can type yum install /sbin/ifconfig to install net-tools package because ‘provides’ database will have that needed information.
What if I tell you that You can achieve similar functionality with pkg(8) tool?
The pkg-provides plugin allows you to query which package provides a particular file directly with pkg(8) tool.
It is even available as pkg-provides package. Below I will show you how to install and configure it. First install the pkg-provides package.
# pkg search provides pkg-provides-0.5.0 Pkg plugin for querying which package provides a particular file # pkg install pkg-provides 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: pkg-provides: 0.5.0 [FreeBSD] Number of packages to be installed: 1 10 KiB to be downloaded. Proceed with this action? [y/N]: y [1/1] Fetching pkg-provides-0.5.0.txz: 100% 10 KiB 9.8kB/s 00:01 Checking integrity... done (0 conflicting) [1/1] Installing pkg-provides-0.5.0... [1/1] Extracting pkg-provides-0.5.0: 100% Message from pkg-provides-0.5.0: ======================= pkg plugin activation ======================== In order to use the pkg-provides plugin you need to enable plugins in pkg. To do this, uncomment the following lines in /usr/local/etc/pkg.conf file and add pkg-provides to the supported plugin list PKG_PLUGINS_DIR = "/usr/local/lib/pkg/"; PKG_ENABLE_PLUGINS = true; PLUGINS [ provides ]; After that run `pkg plugins' to see the plugins handled by pkg`. To update the provides database run `pkg provides -u` ====================================================================
Then configure the /usr/local/etc/pkg.conf file.
# cat << __EOF__ >> /usr/local/etc/pkg.conf PKG_PLUGINS_DIR = "/usr/local/lib/pkg/"; PKG_ENABLE_PLUGINS = true; PLUGINS [ provides ]; __EOF__
Now you have new command called pkg provides as shown below.
# pkg provides usage: pkg provides [-uf] pattern A plugin for querying which package provides a particular file # pkg provides bin/pldd Provides database not found, please update first.
You can update the ‘provides’ database with -u option.
# pkg provides -u Fetching provides database: 100% 29 MiB 700.9kB/s 00:43 Extracting database....success
Example usage of pkg provides plugin.
# pkg provides bin/pldd Name : ptools2-0.5 Desc : Toolset based on Solaris ptools functionality Repo : FreeBSD Filename: /usr/local/bin/pldd Name : linux_base-c7-7.4.1708_6 Desc : Base set of packages needed in Linux mode (Linux CentOS 7.4.1708) Repo : FreeBSD Filename: /compat/linux/usr/bin/pldd # pkg install /compat/linux/usr/bin/pldd Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. pkg: No packages available to install matching '/compat/linux/usr/bin/pldd' have been found in the repositories
Althou its not possible to for example install linux_base-c7 package by typing pkg install /compat/linux/usr/bin/pldd command its possible to check which package contains that file.
Next time you will type the pkg upgrade command you would also see provides database updating
# pkg upgrade Updating FreeBSD repository catalogue... Fetching meta.txz: 100% 944 B 0.9kB/s 00:01 Fetching packagesite.txz: 100% 6 MiB 376.5kB/s 00:18 Processing entries: 100% Fetching provides database: 100% 29 MiB 386.3kB/s 01:18 Extracting database....success FreeBSD repository update completed. 32542 packages processed. All repositories are up to date. Checking integrity... done (0 conflicting) (...)
The pkg provides database takes some notable space in the /var/db/pkg directory.
# file /var/db/pkg/* /var/db/pkg/*/* | sort -n /var/db/pkg/FreeBSD.meta: ASCII text /var/db/pkg/local.sqlite: SQLite 3.x database, user version 34, last written using SQLite version 3015002 /var/db/pkg/provides: directory /var/db/pkg/provides/provides.db: ASCII text /var/db/pkg/repo-FreeBSD.sqlite: SQLite 3.x database, user version 2014, last written using SQLite version 3015002 /var/db/pkg/vuln.xml: XML 1.0 document, UTF-8 Unicode text, with very long lines
If you use ZFS compression like LZ4 then it will not take much as shown below.
# du -csm /var/db/pkg/* 1 /var/db/pkg/FreeBSD.meta 32 /var/db/pkg/local.sqlite 72 /var/db/pkg/provides 33 /var/db/pkg/repo-FreeBSD.sqlite 2 /var/db/pkg/vuln.xml 138 total
… but if You use UFS then that almost 600 MB database may scare you a little π
# du -csmA /var/db/pkg/* 1 /var/db/pkg/FreeBSD.meta 68 /var/db/pkg/local.sqlite 571 /var/db/pkg/provides 52 /var/db/pkg/repo-FreeBSD.sqlite 6 /var/db/pkg/vuln.xml 694 total
Which
While the pkg provides needed information for the files of packages that are not yet installed the pkg which command is the pkg(8) equivalent of the classic UNIX which command. It shows to which package a file belongs to (or not at all).
# pkg which /boot/modules/drm.ko /boot/modules/drm.ko was installed by package drm-fbsd11.2-kmod-4.11g20181210 # pkg which /boot/kernel/drm.ko /boot/kernel/drm.ko was not found in the database
Double Your Gun Double Your Fun
Sometimes its faster to use both ‘whiches’ at the same time to get the needed answer.
# which firefox /usr/local/bin/firefox # pkg which `which firefox` /usr/local/bin/firefox was installed by package firefox-64.0.2,1
Periodic
It may happen that you will see something like that one below.
# pkg install parallel Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. pkg: Cannot get an advisory lock on a database, it is locked by another process
… but You did not launched any other pkg(8) instances, what is going on here? Lets check the ps(1) output.
# ps ax | grep pkg 8540 - S 0:00.00 /bin/sh - /usr/local/etc/periodic/daily/411.pkg-backup 8551 - S 0:00.00 /usr/local/sbin/pkg shell .dump 8555 - D 0:01.08 /usr/local/sbin/pkg shell .dump
The FreeBSD’s periodic scripts are doing their job.
To check which are they look here.
# find /etc/periodic /usr/local/etc/periodic -name \*pkg\* /usr/local/etc/periodic/daily/490.status-pkg-changes /usr/local/etc/periodic/daily/411.pkg-backup /usr/local/etc/periodic/security/460.pkg-checksum /usr/local/etc/periodic/security/410.pkg-audit /usr/local/etc/periodic/weekly/400.status-pkg
If You think that any of those activities are not needed then you may disable them with these values in the /etc/periodic.conf file.
# find /etc/periodic /usr/local/etc/periodic -name \*pkg\* | xargs grep -m 1 -E -o "[a-z_]+_enable" /usr/local/etc/periodic/daily/490.status-pkg-changes:daily_status_pkgng_changes_enable /usr/local/etc/periodic/daily/411.pkg-backup:daily_backup_pkgng_enable /usr/local/etc/periodic/security/460.pkg-checksum:security_status_pkgchecksum_enable /usr/local/etc/periodic/security/410.pkg-audit:security_status_pkgaudit_enable /usr/local/etc/periodic/weekly/400.status-pkg:weekly_status_pkgng_enable
For example if you would like to disable the /usr/local/etc/periodic/daily/490.status-pkg-changes execution you will need to add daily_status_pkgng_changes_enable=yes into the /etc/periodic.conf file.
Lefs chack again for the ps(1) output then.
# ps ax | grep pkg 8574 0 S+ 0:00.00 grep --color pkg
The periodic job has already finished. You may now install your package as usual.
# pkg install parallel 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: parallel: 20171222 Number of packages to be installed: 1 The process will require 3 MiB more space. 1 MiB to be downloaded. Proceed with this action? [y/N]: n #
Stats
While the pkg stats command provides some stats on the installed packages its not that useful to find which packages take most space.
# pkg stats Local package database: Installed packages: 1081 Disk space occupied: 9 GiB Remote package database(s): Number of repositories: 1 Packages available: 32518 Unique packages: 32518 Total size of packages: 78 GiB
There is also pkg size command that will only display space used by packages but without package name … not very useful.
# pkg size | head 10.5MiB 2.06MiB 27.4MiB 2.59MiB 5.17MiB 515KiB 23.2MiB 609KiB 587KiB 127KiB
Also the man page for pkg size does not exist.
# man pkg-size No manual entry for pkg-size
You can use pkg info -as command but it will not only not sort its output in any way – it will also display the space usage in various units like KiB/MiB/GiB which does not help … fortunatelly -h option of sort comes with help.
Using following alias you can sort packages by its space usage. I limited the output to 20 largest packages but feel free to change it to your needs.
# alias pkg-size='pkg info -as | sort -k 2 -h | tail -20 | column -t' # which pkg-size pkg-size: aliased to pkg info -as | sort -k 2 -h | tail -20 | column -t # pkg-size python27-2.7.15 68.2MiB gtk3-3.22.30_4 68.8MiB opencollada-1.6.68_1 75.8MiB py27-ansible-2.7.5 88.6MiB argyllcms-1.9.2_4 92.4MiB webkit2-gtk3-2.22.5 92.9MiB gimp-app-2.10.8_1,1 95.4MiB python36-3.6.8 104MiB samba47-4.7.12 145MiB openjdk8-8.192.26_3 162MiB boost-libs-1.69.0 163MiB thunderbird-60.4.0_1 167MiB firefox-64.0.2,1 174MiB binutils-2.30_7,1 195MiB linux_base-c6-6.10 197MiB gcc6-6.5.0_3 241MiB chromium-71.0.3578.98_2 251MiB libreoffice-6.0.7_4 353MiB virtualbox-ose-5.2.22_2 375MiB llvm60-6.0.1_5 818MiB
Short Names
The pkg(8) tools also support short names for the arguments. For example you do not have to type pkg autoremove. Only the pkg autor part is needed for the command to work.
Example short names blow.
# pkg autor # pkg upg # pkg inf
Metadata
Many problems with pkg(8) are triggered by old metadata database. In case you face any pkg(8) issue first update (forcefully) its database as shown below.
# pkg update -f Updating FreeBSD repository catalogue... Fetching meta.txz: 100% 944 B 0.9kB/s 00:01 Fetching packagesite.txz: 100% 6 MiB 352.9kB/s 00:19 Processing entries: 100% Fetching provides database: 100% 28 MiB 658.3kB/s 00:44 Extracting database....success FreeBSD repository update completed. 31778 packages processed. All repositories are up to date.
For the record – the ‘provides’ database is also updated in such process.
Fixing Broken Dependency
There was time when one missing dependency about vulnerable www/libxul19 package started to torture me for some time.
I was even despered to compile everything with portmaster already.
I started with portmaster --check-depends command, but said no ‘n‘ when asked for fix as it will downgrade a lot of packages needlessly.
# portmaster --check-depends (...) Checking dependencies: evince graphics/evince has a missing dependency: www/libxul19 (...) >>> Missing package dependencies were detected. >>> Found 1 issue(s) in total with your package database. The following packages will be installed: Downgrading perl: 5.14.2_3 -> 5.14.2_2 Downgrading glib: 2.34.3 -> 2.28.8_5 Downgrading gio-fam-backend: 2.34.3 -> 2.28.8_1 Downgrading libffi: 3.0.12 -> 3.0.11 Downgrading gobject-introspection: 1.34.2 -> 0.10.8_3 Downgrading atk: 2.6.0 -> 2.0.1 Downgrading gdk-pixbuf2: 2.26.5 -> 2.23.5_3 Downgrading pango: 1.30.1 -> 1.28.4_1 Downgrading gtk-update-icon-cache: 2.24.17 -> 2.24.6_1 Downgrading dbus: 1.6.8 -> 1.4.14_4 Downgrading gtk: 2.24.17 -> 2.24.6_2 Downgrading dbus-glib: 0.100.1 -> 0.94 Installing libxul: 1.9.2.28_1 The installation will require 66 MB more space 38 MB to be downloaded >>> Try to fix the missing dependencies [y/N]: n >>> Summary of actions performed: www/libxul19 dependency failed to be fixed >>> There are still missing dependencies. >>> You are advised to try fixing them manually. >>> Also make sure to check 'pkg updating' for known issues.
Lets see what pkg(8) shows we have installed.
# pkg info | grep libxul libxul-10.0.12 Mozilla runtime package that can be used to bootstrap XUL+XPCOM apps # pkg info -qoa | grep libxul www/libxul
So the problem is that we have installed www/libxul instead of www/libxul19 and that is why portmaster (and not only) complains about it.
Before pkg(8) was introduced it was easy just to grep -r the entire /var/db/pkg directory with its ‘file database’ but now its quite more complicated as the package database is kept in SQLite database. Using pkg shell command You can connect to that database. Lets check what we can find there.
# pkg shell SQLite version 3.7.13 2012-06-11 02:05:22 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .databases seq name file --- --------------- ---------------------------------------------------------- 0 main /var/db/pkg/local.sqlite sqlite> .tables categories licenses pkg_directories scripts deps mtree pkg_groups shlibs directories options pkg_licenses users files packages pkg_shlibs groups pkg_categories pkg_users sqlite> .header on sqlite> .mode column sqlite> pragma table_info(deps); cid name type notnull dflt_value pk ---------- ---------- ---------- ---------- ---------- ---------- 0 origin TEXT 1 1 1 name TEXT 1 0 2 version TEXT 1 0 3 package_id INTEGER 0 1 sqlite> .quit
So now we know that ‘deps‘ table is probably what we are looking for ;).
As pkg shell is quite limited for SQLite ‘browsing’ I will use the sqlite3 command itself. By limited I mean that You can not type pkg shell "select * from deps;" query, You first need to start pkg shell and then You can type your query.
# sqlite3 -column /var/db/pkg/local.sqlite "select * from deps;" | grep libxul www/libxul19 libxul 1.9.2.28_1 104
The second column is name so lets try to use it.
sqlite3 -header -column /var/db/pkg/local.sqlite "select * from deps where name='libxul';" origin name version package_id ------------ ---------- ---------- ---------- www/libxul19 libxul 1.9.2.28_1 104
So now we have the ‘problematic’ dependency entry nailed, lets modify it a little to the real installed packages state.
# sqlite3 /var/db/pkg/local.sqlite "update deps set origin='www/libxul' where name='libxul';" # sqlite3 /var/db/pkg/local.sqlite "update deps set version='10.0.12' where name='libxul';"
You can of course use the ‘official’ way by using the pkg shell command.
# pkg shell SQLite version 3.7.13 2012-06-11 02:05:22 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> update deps set origin='www/libxul' where name='libxul'; sqlite> update deps set version='10.0.12' where name='libxul'; sqlite> .header on sqlite> .mode column sqlite> select * from deps where name='libxul'; origin name version package_id ---------- ---------- ---------- ---------- www/libxul libxul 10.0.12 104 sqlite> .quit
Now portmaster is happy and does not complain about any missing dependencies.
# portmaster --check-depends (...) Checking dependencies: zenity Checking dependencies: zip Checking dependencies: zsh #
Viola! Problem solved π
… but pkg(8) has a tool for that already π
Its called pkg set and two most useful options from man pkg-set are.
-n oldname:newname, --change-name oldname:newname Change the package name of a given dependency from oldname to newname. (...) -o oldorigin:neworigin, --change-origin oldorigin:neworigin Change the port origin of a given dependency from oldorigin to neworigin. This corresponds to the port directory that the package originated from. Typically, this is only needed for upgrading a library or package that has MOVED or when the default version of a major port dependency changes. (DEPRECATED) Usually this will be explained in /usr/ports/UPDATING. Also see pkg-updating(8) and EXAMPLES.
In our case we would use pkg set -o www/libxul19:www/libxul command.
Not sure if it will solve that problem in the same way as I also updated the version in the database.
UPDATING
If you get into any trouble with the pkg upgrade command then you should also check latest version of the /usr/ports/UPDATING file – available after updating the Ports tree with portsnap fetch update command for example.
It describes what important has changed in Ports (and packages as packages are built from Ports).
# less /usr/ports/UPDATING (...) 20180518: AFFECTS: users of sysutils/ansible* AUTHOR: lifanov@FreeBSD.org Ansible ports are now flavored. Package names for Ansible changed to include python version. Poudriere and package users don't need to do anything. To rename an installed package to match the new naming scheme, for example, for ansible24, run: # pkg set -n ansible24:py27-ansible24 (...) 20180214: AFFECTS: users of lang/ruby23 AUTHOR: swills@FreeBSD.org The default ruby version has been updated from 2.3 to 2.4. If you compile your own ports you may keep 2.3 as the default version by adding the following lines to your /etc/make.conf file: # # Keep ruby 2.3 as default version # DEFAULT_VERSIONS+=ruby=2.3 If you wish to update to the new default version, you need to first stop any software that uses ruby. Then, you will need to follow these steps, depending upon how you manage your system. If you use pkgng, simply upgrade: # pkg upgrade If you use portmaster, install new ruby, then rebuild all ports that depend on ruby: # portmaster -o lang/ruby24 lang/ruby23 # portmaster -R -r ruby-2.4 If you use portupgrade, install new ruby, then rebuild all ports that depend on ruby: # pkg delete -f ruby portupgrade # make -C /usr/ports/ports-mgmt/portupgrade install clean # pkg set -o lang/ruby23:lang/ruby24 # portupgrade -x ruby-2.4.\* -fr lang/ruby24 (...)
The pkg(8) framework also has a tool for that with pkg updating command. Check man pkg-updating page for details. The most common use case would be using the -d argument with date as shown below.
# pkg updating -d 20190101 20190103: AFFECTS: users of multimedia/vlc* AUTHOR: riggs@FreeBSD.org The multimedia/vlc port has been upgraded to 3.0.5, the latest upstream release. Subsequently, multimedia/vlc-qt4 and multimedia/vlc3 have been retired and removed from the ports tree. Users who previously used multimedia/vlc3 might want to switch to multimedia/vlc with the following commands: # pkg install multimedia/vlc or # portmaster -o multimedia/vlc multimedia/vlc3 or # portupgrade -o multimedia/vlc multimedia/vlc3
You may as well check the UPDATING file online at the https://www.freshports.org/UPDATING address.
Bulletproof Upgrades with ZFS Boot Environments
To be absolutely sure that you will have a working system no matter what will went wrong with the pkg upgrade command just use the ZFS Boot Environments. I have made talks in Poland at PBUG and in Netherlands at NLUUG about its features not so long ago. The latest PDF presentation is still available at the https://is.gd/BECTL link.
The procedure with beadm command looks like that.
# beadm create safepoint Created successfully # beadm list BE Active Mountpoint Space Created 11.2-RELEASE NR / 5.7G 2018-12-01 13:09 safepoint - - 316.0K 2019-01-16 23:03 # pkg upgrade
Now if anything wrong will not happen You still have fully working system under the safepoint boot environment name.
Just reboot into it (select it in the FreeBSD loader) and you are back with working system, like you would be back in time with time machine.
Query
You can also use pkg query command to seek for intormation you need.
For example to ’emulate’ the pkg info -r pkg-name argument which displays the list of packages which require pkg-name you can use pkg query command as shown below.
# pkg info -r sqlite3 sqlite3-3.26.0: colord-gtk-0.1.26 py27-sqlite3-2.7.15_7 freeciv-2.5.10 colord-1.3.5 libsoup-2.62.3 libsoup-gnome-2.62.3 subversion-1.11.0_1 nss-3.41_1 webkit-gtk2-2.4.11_19 filezilla-3.36.0_1 epiphany-3.28.5_1 darktable-2.4.4_3 aria2-1.34.0_1 webkit2-gtk3-2.22.5 qt5-webkit-5.212.0.a2_17 qt5-sqldrivers-sqlite3-5.12.0 hugin-2018.0.0_6 pidgin-2.13.0 thunderbird-60.4.0_1 midori-0.7.0 firefox-64.0.2,1 # pkg query -e '%n = sqlite3' %ro graphics/colord-gtk databases/py-sqlite3 games/freeciv graphics/colord devel/libsoup devel/libsoup-gnome devel/subversion security/nss www/webkit-gtk2 ftp/filezilla www/epiphany graphics/darktable www/aria2 www/webkit2-gtk3 www/qt5-webkit databases/qt5-sqldrivers-sqlite3 graphics/hugin net-im/pidgin mail/thunderbird www/midori www/firefox
If you would like to know when each package was installed for the first time then use this spell below.
# pkg query "%t %n-%v" \ | sort -n \ | while read timestamp pkgname do echo "$(date -r $timestamp) $pkgname" done | ( head; echo; tail ) Fri Jul 7 14:17:29 CEST 2017 libpciaccess-0.13.5 Fri Jul 7 14:17:35 CEST 2017 libedit-3.1.20170329_2,1 Fri Jul 7 14:18:09 CEST 2017 font-util-1.3.1 Fri Jul 7 14:18:10 CEST 2017 xcb-util-0.4.0_2,1 Fri Jul 7 15:26:56 CEST 2017 xcb-util-renderutil-0.3.9_1 Fri Jul 7 15:26:57 CEST 2017 dejavu-2.37 Fri Jul 7 15:27:00 CEST 2017 font-misc-meltho-1.0.3_3 Fri Jul 7 15:27:02 CEST 2017 font-misc-ethiopic-1.0.3_3 Fri Jul 7 15:27:06 CEST 2017 font-bh-ttf-1.0.3_3 Fri Jul 7 15:27:08 CEST 2017 tpm-emulator-0.7.4_2 Sun Jan 13 20:48:01 CET 2019 firefox-64.0.2,1 Sun Jan 13 20:48:01 CET 2019 htop-2.2.0_1 Wed Jan 16 23:08:21 CET 2019 vlc-3.0.6,4 Wed Jan 16 23:08:21 CET 2019 xdg-utils-1.1.3 Wed Jan 16 23:08:25 CET 2019 phonon-qt4-4.10.2 Wed Jan 16 23:08:25 CET 2019 physfs-3.0.1 Wed Jan 16 23:08:25 CET 2019 py27-pyasn1-0.4.5 Wed Jan 16 23:08:26 CET 2019 chromium-71.0.3578.98_2 Wed Jan 16 23:08:26 CET 2019 moreutils-0.63 Wed Jan 16 23:08:26 CET 2019 p5-URI-1.76
You can also display packages that will not be removed by pkg autoremove command because You installed them directly.
# pkg query -e "%a != 1" "%n" | tail xmp xorg xprintidle xterm xxkb youtube_dl zenity zfs-stats zip zsh
Rosetta Stone
The FreeBSD Wiki page also provides some table but the information is incomplete.
Thus I copied the table and filled the missing data.
Below you will find the updated Rosetta Stone between old pkg_* tools compared to current pkg(8) framework.
Function | Old pkg_* Tools | New pkg(8) Tools |
List of installed packages. | pkg_info | pkg info |
Basic info about package. | pkg_info pkgname-pkgversion | pkg info pkgname pkg info category/name pkg info pkgname-pkgversion |
Detailed info about package. | N/A | pkg info -f pkgname pkg info -f category/name pkg info -f pkgname-pkgversion |
List all files in installed package. | pkg_info -L pkgname-pkgversion | pkg info -l pkgname pkg info -l category/name pkg info -l pkgname-pkgversion |
Find which package provides file. | pkg_info -W /path/to/my/file | pkg which /path/to/my/file |
Install local package. | pkg_add ./localpkg.tbz | pkg add ./localpkg.txz |
Install remote package. | pkg_add -r mypackage | pkg install mypackage pkg install category/name pkg install pkgname-pkgversion |
Search for remote package. | ls /usr/ports/* | grep mypackage | pkg search mypackage pkg search category/name pkg search pkgname-pkgversion |
Search for detailed info about remote package. | make search name=mypackage make search key=mypackage |
pkg search -f mypackage pkg search -f category/name pkg search -f pkgname-pkgversion |
Reverse deps of installed package. | pkg_info -R pkgname-pkgversion | pkg info -r mypackage pkg info -r category/name pkg info -r pkgname-pkgversion |
Deps of installed package. | pkg_info -r pkgname-pkgversion | pkg info -d mypackage pkg info -d category/name pkg info -d pkgname-pkgversion |
Remove unused packages install as dep. | N/A | pkg autoremove |
Binary upgrade installed packages. | pkg_upgrade (FreeBSD Ports) | pkg upgrade |
Create remote repository. | N/A | pkg repo /directory/with/packages |
Manipulate packages in jail. | N/A | pkg -j |
Manipulate packages in chroot. | pkg_add -C | pkg -c |
Info about installed packages using RE. | pkg_info -x | pkg info -x |
Info about installed packages using extended RE. | pkg_info -X | pkg info -X |
Info about installed packages using globbing. | pkg_info | pkg info -g |
Check for known vulnerabilities. | portaudit (FreeBSD Ports) | pkg audit |
Out of date packages. | pkg_version -l < | pkg version -l < |
Out of date packages. | pkg_version -Il < | pkg version -Il < |
Out of date packages compared to remote repo. | N/A | pkg upgrade -n |
Statistic about installed packages. | N/A | pkg stat |
Checking for missing dependency (with fix). | N/A | pkg check -d |
Port origin. | pkg_info -o | pkg info -o |
If you know any other useful pkg(8) spells then let me know π
Pingback: In Other BSDs for 2019/01/26 – DragonFly BSD Digest
Pingback: Fix Broken Dependency on FreeBSD | ππππππππ
Nice list π
One I find quite handy is the bootstrap ability – there’s been a few issues with pkg recently where i’ve had to force reinstall the pkg binary, and that is easily achieved with a pkg bootstrap -f
LikeLike
Yes, sometimes it helps, but I did not yet find a situation that pkg update -f would not solve π
LikeLike