Back to lessons

Linux Survival Basics

Check One Installed Package Cleanly

You need to confirm whether one package is installed and capture its exact installed version without noisy apt output.

Command

dpkg-query -W -f='${Status} ${Version}\n' openssl

What changed

Nothing changes. dpkg-query reads the local dpkg database for one package.

Danger

safe

When to use it

Use in runbooks, support tickets, and package audits where one exact installed version matters.

When not to use it

Do not use it to find the newest available version; use apt policy for candidate information.

Undo or recovery

No undo needed because the command is read-only.

Expected output

A status and version line such as install ok installed 3.0.13-0ubuntu3.5.

demo script

Disposable terminal steps

  1. dpkg-query -W -f='${Status} ${Version}\n' openssl
  2. dpkg-query -W -f='${Status} ${Version}\n' nginx

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ dpkg-query -W -f='${Status} ${Version}\n' openssl
install ok installed 3.0.13-0ubuntu3.5
::exit-code::0
$ dpkg-query -W -f='${Status} ${Version}\n' nginx
install ok installed 1.24.0-2ubuntu7.3
::exit-code::0

YouTube Short

Check one package.

When you only care about one package, query dpkg directly and get the installed status plus exact version.

LinkedIn hook

For one package, dpkg-query gives a clean status line.

Question: For one package, do you reach for dpkg-query or apt first?

experiments

A/B tests to run

Metric: copy_rate

A: One package. Clean answer.

B: Exact installed version.