How to List Installed Packages on Ubuntu with apt and dpkg-query

On Ubuntu, use apt list --installed when you want a readable list of installed packages, and use dpkg-query when you need an exact status check or structured output for a script. The best command depends on whether you know the package name, need to identify the package that owns a file, or want to separate manually and automatically installed packages.

List all installed Deb packages

To display installed packages together with their versions, architectures, and repository status, run:

apt list --installed

If the list is long, pass it to less. You can also supply a package-name pattern directly.

apt list --installed | less
apt list --installed 'nginx*'

The apt command is designed primarily as an interactive interface for people. For inventory files, comparisons, and scripts, dpkg-query is usually a better choice because its output format can be specified explicitly.

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

Check whether a specific package is installed

When you know the exact package name

The following command displays the dpkg database record for nginx. A package that is fully installed normally includes Status: install ok installed in the output.

dpkg-query -s nginx

To print only the current status in a compact form, request the status field directly.

dpkg-query -W -f='${db:Status-Status}\n' nginx

The expected output for a normally installed package is installed. If the package does not exist in the local database, the command returns a nonzero exit status. Scripts should check the exit status instead of relying only on displayed text.

When you want to search similar package names

dpkg-query -l accepts shell wildcard patterns. Quote the pattern so that the shell does not expand it before dpkg-query receives it.

dpkg-query -l 'nginx*'

The first three characters in the output describe the desired action, current status, and error status. The common ii combination means that installation is desired and the package is currently installed.

Code Meaning
ii The package is selected for installation and is currently installed correctly.
rc The package files have been removed, but configuration files remain.
iU The package has been unpacked, but configuration has not been completed.
Uppercase status The package may be in an incomplete or seriously inconsistent state. Check the detailed status and package-management logs.

Check the installed version and repository candidate

Print only the installed version

dpkg-query -W -f='${binary:Package}\t${Version}\n' curl

The binary:Package field appends an architecture qualifier when it is needed for a Multi-Arch package. It is safer than the plain Package field when you compare versions or inventories across systems.

Compare the installed and candidate versions

apt-cache policy curl

Installed is the version currently present on the system, while Candidate is the version selected from the enabled repositories. Repository metadata may be stale, so run sudo apt update before using this result to decide whether an update is available.

Find files installed by a package

List files recorded for a package

dpkg-query -L nginx

This command lists files recorded for the package in the dpkg database. It does not necessarily include logs, caches, uploads, databases, or other files that an application creates after installation.

Identify the package that owns a file

dpkg-query -S /usr/bin/curl

If the path is a symbolic link, check the resolved target as well.

readlink -f /usr/bin/python3
dpkg-query -S "$(readlink -f /usr/bin/python3)"

dpkg-query -S searches records for installed packages only. To find which repository package provides a file that is not installed, use a separate indexed search tool such as apt-file.

Separate manually and automatically installed packages

APT records whether a package was selected directly or installed automatically as a dependency.

apt-mark showmanual
apt-mark showauto

The showmanual result is not simply a history of applications that a person installed later. It can also contain metapackages and components that the original Ubuntu installation marked as manual. Do not infer a package's purpose or installation history from this list alone.

An automatically installed dependency may become eligible for autoremove when no manually installed package needs it. Always review the proposed changes before removing anything.

sudo apt autoremove --dry-run

Save an installed-package inventory to a file

For troubleshooting or comparing systems, save the package name, version, and architecture as tab-separated data.

dpkg-query -W -f='${binary:Package}\t${Version}\t${Architecture}\n' \
  | sort > installed-packages.tsv

Compare inventories from two systems or two points in time with:

diff -u installed-packages-before.tsv installed-packages-after.tsv

This file is an inventory of a system at a particular time, not a complete backup or recovery method. Another Ubuntu release may not provide the same versions, and repository definitions, Personal Package Archives (PPAs), Snap packages, local configuration, and application data must be handled separately.

Distinguish Deb and Snap packages

apt and dpkg-query inspect Deb packages. Applications installed as Snaps appear in a separate list.

snap list

A complete software inventory may also need to cover container images, language-specific package managers, manually installed programs, and other deployment methods.

Command summary by task

Task Recommended command
List all installed Deb packages apt list --installed
Produce structured names and versions dpkg-query -W -f='format'
Check a specific package's status dpkg-query -s PACKAGE
Compare installed and candidate versions apt-cache policy PACKAGE
List files installed by a package dpkg-query -L PACKAGE
Identify the owner of a file dpkg-query -S FILE
List packages marked as manual apt-mark showmanual
List installed Snap packages snap list

Important limitations and safety checks

  • A search with grep may match several packages that contain the same text in their names. Use dpkg-query -s or -W for an exact installation check.
  • dpkg-query -l can show packages that have been removed but still have configuration files. Read the status columns instead of treating every row as installed.
  • An installed package list does not tell you whether its service is running. Check a service separately with its management tool, such as systemctl status.
  • Before removing a package, review dependencies, metapackages, and any operating-system functions that may rely on it.

Official references

More in This Category
Ubuntu Administration Memo: Essential Commands and Configuration Notes

Ubuntu Administration Memo: Essential Commands and Configuration Notes

A practical Ubuntu administration reference covering frequently used commands, configuration files, package management, services, networking, storage, and troubleshooting checks.

How to List Installed Packages on Ubuntu with apt and dpkg-query

How to List Installed Packages on Ubuntu with apt and dpkg-query

Learn how to list installed Deb packages on Ubuntu with apt and dpkg-query, verify package status and versions, identify file ownership, and separate manual from automatic installations. The guide also covers inventory exports and Snap packages.

Ubuntu LTS Lifecycle

Ubuntu LTS Lifecycle

Learn how Ubuntu LTS support progresses from five years of standard security maintenance to ten years with Ubuntu Pro ESM and up to fifteen years with the Legacy add-on. The guide also lists lifecycle dates and shows how to check a system's coverage.