How to find which package provides a file¶
Use this guide in either of two situations:
- A file exists on the system, such as a command, a library or a configuration file, and you need to know which package installed it, for example to reinstall it, read its documentation or report a bug.
- A command or file you need is missing, and you need to know which package to install to get it.
Before you begin¶
- You need a shell on the machine. Searching for files in packages that aren't installed needs
sudothe first time, to download the file lists. - Replace
<FILE>with the absolute path of the file, for example/usr/bin/lsblk.
Find the package that owns an installed file¶
-
If you only know a command's name, find its path first:
-
Ask the package database which package owns the file:
dpkgmatches the path as it is recorded in the package, not as it resolves on disk. On Debian 13 and Ubuntu 26.04,/binis a symbolic link to/usr/binand packages record their files under/usr, sodpkg -S /bin/lsblkreportsno path found matching pattern. Resolve the path first if that happens:Given a name instead of a path,
dpkg -Slists every installed file whose path contains it, which is useful when you know only part of the name.Add
--qf '%{NAME}\n'to print only the package name.qfilefromapp-portage/portage-utilsreads Portage's installed-package database directly. Gentoo records each file under the path its package installed it to, which on a merged-/usrsystem is often still/binor/sbin.qfile /usr/bin/lsblktherefore prints nothing, while the recorded path works:Given only a file name,
qfilematches it in any directory, which avoids the problem but can list several files:$ qfile lsblk sys-apps/util-linux: /usr/share/bash-completion/completions/lsblk sys-apps/util-linux: /bin/lsblkequery belongs, fromapp-portage/gentoolkit, answers the same question with the same path rules. -
If the command reports that no package owns the file, the file wasn't installed by the package manager. Common reasons are software installed by hand under
/usr/localor/opt, files generated at installation or boot time (for example/etc/hostnameor/etc/machine-id), and files created by an administrator.
Find the package that provides a missing file¶
This needs a list of the files in every package in the repositories, not only the installed ones.
The example looks for the dig DNS lookup command.
-
Install
apt-fileand download the file lists for the configured repositories: -
Search for the path.
apt-file searchmatches any path that contains the pattern;-xtreats it as a regular expression, which lets you match the end of the path exactly:
On Ubuntu, typing a missing command in an interactive shell also prints the package that provides it, through the command-not-found package.
dnf downloads file lists with the repository metadata, so no extra tool is needed.
Give it the full path, or a glob such as '*/dig' when you don't know the directory:
$ dnf provides /usr/bin/dig
bind-utils-32:9.18.33-15.el10_2.1.x86_64 : Utilities for querying DNS name servers
Repo : appstream
Matched from:
Filename : /usr/bin/dig
dnf lists every version in the repositories that contains the file; the package name is what you install (here bind-utils).
-
Download the file databases for the configured repositories:
-
Search for the path or for a file name:
Given only a name,
pacman -F diglists every package with a file of that name in any directory.
The file databases aren't refreshed by pacman -Syu; run sudo pacman -Fy again before searching if they're old.
Gentoo has no index of the files that uninstalled packages would install, because the files depend on how each package is built (its USE flags).
Search the ebuild repository by package name or description instead, starting from what the command is part of: dig is part of BIND.
A leading % makes the search term a regular expression:
$ emerge --search '%^bind$'
* net-dns/bind
Latest version available: 9.20.30
Latest version installed: [ Not Installed ]
Size of files: 5,864 KiB
Homepage: https://www.isc.org/bind/
Description: Berkeley Internet Name Domain - Name Server
License: MPL-2.0
emerge --searchdesc (-S) also searches the descriptions.
Results marked [ Masked ] aren't installable as they are; net-dns/bind-tools, for example, is masked, and dig is now installed by net-dns/bind.
The package app-portage/pfl provides e-file, which queries a community-run online index of the files in Gentoo packages; it isn't covered here.
Verify¶
Install the package you found and check that the file now exists and belongs to it:
Troubleshooting¶
apt-file searchprints nothing- The file lists haven't been downloaded, or are for different repositories than you expect. Run
sudo apt-file updateagain after changing repositories. Check that the path is spelt as packages install it: under/usr/bin, not/bin, on Debian 13 and Ubuntu 26.04. dnf providesreportsNo matches found- The file isn't in any enabled repository. A disabled repository may provide it. On Rocky Linux, the CRB repository is disabled by default (on AlmaLinux 10 it's enabled);
dnf --enablerepo=crb provides <FILE>also searches it, without enabling it permanently. pacman -Freportserror: no file databasesor finds nothing- The file databases were never downloaded, or are out of date. Run
sudo pacman -Fy. - The file is provided by more than one package
- This is normal for alternatives such as
vi,editoror mail transfer agents. Pick the package from the distribution's documentation for the feature you want. To see which installed program currently provides a generic name such aseditor, runupdate-alternatives --display <NAME>on Debian and Ubuntu oralternatives --display <NAME>on the RHEL family, where<NAME>is the generic name; it shows the path of the selected program, anddpkg -Sorrpm -qfon that path shows its package.
Related¶
- Reference: Package manager commands
- Reference: Repository configuration
- Explanation: How package management works
- Explanation: Binary and source distributions
- How-to: How to add a third-party repository safely
- How-to: How to hold a package at its current version
- How-to: How to roll back a package update