How to fix dpkg-query: no packages found matching package-name in APT
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.
Quick fix
Fixes dpkg-query: no packages found matching package-name
apt-cache search package-name- Verify the exact package name
- Update your package lists
- Install the missing package
- Properly quote wildcard patterns in scripts
apt-cache search package-namedpkg-query: no packages found matching package-name
What this error means
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.
Typical symptoms
- Scripts or tools fail when checking if a package is installed
- dpkg-query command returns exit code 1 with the "no packages found" message
- Installation scripts or automation fail partway through when probing for package presence
- Wildcard patterns with dpkg-query don't return expected matches
Common causes
- The package you're querying is not installed on the system
- The package name is misspelled or uses a different name than expected
- The actual package name differs from the program/tool name (e.g., the binary is 'python' but package is 'python3')
- Wildcard patterns in dpkg-query are being expanded by the shell before being passed to dpkg-query
- Using dpkg-query with an older or incompatible package name format
How to fix "dpkg-query: no packages found matching package-name"
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.
Advanced notes
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.
Frequently asked questions
- What does "dpkg-query: no packages found matching package-name" mean?
- 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.
- How do I fix "dpkg-query: no packages found matching package-name"?
- 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.
- What causes "dpkg-query: no packages found matching package-name"?
- The package you're querying is not installed on the system The package name is misspelled or uses a different name than expected The actual package name differs from the program/tool name (e.g., the binary is 'python' but package is 'python3')
- Is the "dpkg-query: no packages found matching package-name" error serious?
- It is a low-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚APT Official Documentation
- 📖Linux man-pages: dpkg-query(1) manual(Official Docs)
- 📖Ubuntu Manpage: dpkg-query - query the dpkg database(Official Docs)
- 📖Debian Manpages: dpkg-query(1) documentation(Official Docs)