The "dpkg-query: no packages found matching" error occurs when you try to query or check a package that isn't installed on your Debian/Ubuntu system. This is typically a lookup error rather than a system failure.
The dpkg-query tool is the database query interface for the Debian Package Manager (dpkg). When you run dpkg-query on a package name, it searches the local installed package database. If the package isn't in that database, dpkg-query reports that no packages match the search pattern. This is different from a package being unavailable in repositories—it specifically means the package isn't currently installed on your system. The error happens at the query stage, before any installation or system interaction occurs.
First, search for the package in your system's package repositories to confirm the correct name:
apt-cache search package-nameThis searches available packages in your repositories. Replace 'package-name' with a partial or full name. This shows you what packages are available for installation.
If you already think the package might be installed, list all packages with a grep filter:
dpkg -l | grep partial-nameThis shows all packages that have been installed on your system with "partial-name" in their name.
Before installing, refresh your package database to ensure you have the latest package information:
sudo apt updateThis downloads the latest package lists from your configured repositories. Without this, apt might not know about recently added packages.
Once you've confirmed the correct package name, install it:
sudo apt install package-nameReplace 'package-name' with the exact name from your apt-cache search results. After installation, dpkg-query will find it.
You can verify the installation succeeded:
dpkg-query -l package-nameIf successful, this displays the package details instead of the "no packages found" error.
If you're using dpkg-query with wildcards in a script, the shell may be interpreting the wildcards as filename patterns. Always quote the pattern:
# WRONG - shell expands the wildcard before dpkg-query sees it
dpkg-query -l libc6*
# CORRECT - pass the literal pattern to dpkg-query
dpkg-query -l 'libc6*'Single quotes prevent shell expansion, allowing dpkg-query to process the wildcard pattern correctly and match multiple packages.
For more detailed status information about a specific package, use dpkg with the -s flag:
dpkg -s package-nameIf the package is installed, this shows its status, version, and metadata. If not installed, it returns an error with helpful information about why it can't be found.
This is useful in scripts when you need detailed information beyond just checking presence/absence.
Exit Codes: dpkg-query returns specific exit codes. Exit code 1 indicates "The requested query failed either fully or partially, due to no file or package being found." Exit code 2 indicates fatal errors from invalid command-line usage or system interactions.
Database Location: The dpkg package database is located at /var/lib/dpkg by default. You can query a different database location using the --admindir option if working with a custom setup.
APT vs dpkg-query: Modern systems prefer using 'apt show package-name' over dpkg-query for users, as apt automatically refreshes the available package list. dpkg-query is best for checking what's installed, while apt is better for discovering what's available in repositories.
Exit Code Handling in Scripts: When writing shell scripts, check the exit code of dpkg-query. Use 'if dpkg-query -l package-name 2>/dev/null; then' to silently check if a package exists without displaying the error message.
E: Cannot set to hold: package 'package-name' is not installed
How to fix "Cannot set to hold" error when package is not installed in APT
debconf: unable to initialize frontend: Dialog
How to fix "debconf: unable to initialize frontend: Dialog" in APT
E: Could not connect to proxy server
Could not connect to proxy server
dpkg: serious warning: files list file for package 'package-name' contains empty filename
How to fix "files list file contains empty filename" in APT
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt