How do I find the package that provides a file?

Solution 1:

You can use dpkg command to find out which installed package owns a file:

From man dpkg:

-S, --search filename-search-pattern...
                  Search for a filename from installed packages.

Example:

$ dpkg -S /bin/ls
coreutils: /bin/ls

You can either search with a full path or with just the filename.

If you wish to search for files not yet installed on your computer, you can use the Ubuntu Packages Search, or apt-file as described in a different answer.

Solution 2:

The apt-file command can do this for you from the command line. I use it frequently when building packages from source. For files provided by packages that are already installed on your system, apt-cache is another choice.

To install apt-file, do:

sudo apt-get install apt-file

Then, you need to update it's database:

sudo apt-file update

And, finally, search the file:

$ apt-file find kwallet.h
kdelibs5-dev: /usr/include/kwallet.h
libkf5wallet-dev: /usr/include/KF5/KWallet/kwallet.h

However a much friendlier way is to use the Ubuntu Packages Search website. They have an option to "search the contents of packages" for a specific filename.

Solution 3:

There's also apt-file for looking up files in packages that aren't installed. For example:

apt-file list packagename

Solution 4:

You can search the contents of packages included in the various Ubuntu releases on the Ubuntu Packages website. Look under the heading "Search the contents of packages".

For example, here are the search results for libnss3.so in focal (20.04):

http://packages.ubuntu.com/search?searchon=contents&keywords=libnss3.so&mode=exactfilename&suite=focal&arch=any

Solution 5:

You mean, which package and not which application. The application is your package manager, e.g. Software Center.

Using dpkg:

dpkg -S /usr/lib/tracker/tracker-store
dpkg -S tracker-extract
dpkg -S tracker-miner-fs

Example

% dpkg -S /usr/lib/tracker/tracker-store
tracker: /usr/lib/tracker/tracker-store

Using apt-file:

apt-file search /usr/lib/tracker/tracker-store

or also possible:

apt-file search --regex /tracker-extract$
apt-file search --regex /tracker-miner-fs$

Example

% apt-file search /usr/lib/tracker/tracker-store
tracker: /usr/lib/tracker/tracker-store

Or online here, in the section Search the contents of packages.

enter image description here

Example

enter image description here