Skip to content
Latchkey

dpkg-query: Usage, Options & Common CI Errors

dpkg-query reports what Debian packages are installed and which files they own.

dpkg-query is the scriptable way to check installed state on Debian/Ubuntu - handy in CI to assert a package is present or to find which package owns a file.

What it does

dpkg-query reads the dpkg database and reports installed packages, their versions, status, and the files they ship. It is read-only and is the precise tool for "is this installed?" checks in a pipeline (more scriptable than dpkg -l, which is paginated/formatted).

Common usage

Terminal
dpkg-query -W -f='${Version}\n' curl        # print just the version
dpkg-query -l 'nginx*'                         # list matching packages
dpkg-query -L curl                             # files installed by curl
dpkg-query -s curl                             # full status block
dpkg-query -S /usr/bin/curl                    # which package owns a file

Common errors in CI

dpkg-query exits 1 when no package matches, e.g. "dpkg-query: no packages found matching X" - under set -e that aborts the step, so guard it (dpkg-query -W X 2>/dev/null || echo missing). The -f / --showformat string uses fields like ${Version} and ${Status}; an unescaped $ gets eaten by the shell, so single-quote the format. dpkg-query -S only finds files that belong to an installed package (not files you created).

Options

FlagWhat it does
-W / --showShow packages, formatted with -f
-f / --showformatCustom output format (${Version}, ${Status})
-l / --listList installed packages (paginated table)
-L / --listfilesList files a package installed
-s / --statusShow the full status entry
-S / --searchFind which package owns a path

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →