Back to lessons

Linux Survival Basics

List Installed Package Versions

You need a deterministic list of installed Debian packages, versions, and architectures for comparison or incident notes.

Command

dpkg-query -W -f='${Package}\t${Version}\t${Architecture}\n' | sort

What changed

Nothing changes. dpkg-query reads the local package database and prints a sorted inventory.

Danger

safe

When to use it

Use before upgrades, after incidents, during fleet comparison, or when handing a host to another operator.

When not to use it

Do not use it to discover available updates; use apt list --upgradable for candidate upgrades.

Undo or recovery

No undo needed because the command is read-only.

Expected output

Sorted package, version, and architecture rows.

demo script

Disposable terminal steps

  1. dpkg-query -W | head
  2. dpkg-query -W -f='${Package}\t${Version}\t${Architecture}\n' | sort

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ dpkg-query -W | head
base-files	13ubuntu10.2	amd64
bash	5.2.21-2ubuntu4	amd64
curl	8.5.0-2ubuntu10.6	amd64
libc6	2.39-0ubuntu8.4	amd64
linux-image-6.8.0-60-generic	6.8.0-60.63	amd64
nginx	1.24.0-2ubuntu7.3	amd64
openssl	3.0.13-0ubuntu3.5	amd64
python3	3.12.3-0ubuntu2	amd64
zlib1g	1:1.3.dfsg-3.1ubuntu2	amd64
zlib1g:i386	1:1.3.dfsg-3.1ubuntu2	i386
::exit-code::0
$ dpkg-query -W -f='${Package}\t${Version}\t${Architecture}\n' | sort
base-files	13ubuntu10.2	amd64
bash	5.2.21-2ubuntu4	amd64
curl	8.5.0-2ubuntu10.6	amd64
libc6	2.39-0ubuntu8.4	amd64
linux-image-6.8.0-60-generic	6.8.0-60.63	amd64
nginx	1.24.0-2ubuntu7.3	amd64
openssl	3.0.13-0ubuntu3.5	amd64
python3	3.12.3-0ubuntu2	amd64
zlib1g	1:1.3.dfsg-3.1ubuntu2	amd64
zlib1g:i386	1:1.3.dfsg-3.1ubuntu2	i386
::exit-code::0

YouTube Short

Export installed versions.

When a machine drifts, do not trust memory. Query dpkg and sort package, version, and architecture.

LinkedIn hook

A package inventory beats memory when a server is drifting.

Question: Do you keep package inventories before risky maintenance windows?

experiments

A/B tests to run

Metric: copy_rate

A: Inventory before change.

B: Stop guessing installed versions.