How do I find the package that provides a file?
Emily Wong
Simple enough question: is there some shell command (or GUI method) I can use that, given the path to a file on my system, tells me what package put it there? Assuming the file did in fact come from a package, that is.
Bonus question: what if it's a file that isn't installed on my system? Is there, say, a website that will let me look up a file and see what packages, if any, provide it?
310 Answers
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/lsYou 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.
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-fileThen, you need to update it's database:
sudo apt-file updateAnd, finally, search the file:
$ apt-file find kwallet.h
kdelibs5-dev: /usr/include/kwallet.h
libkf5wallet-dev: /usr/include/KF5/KWallet/kwallet.hHowever 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.
7There's also apt-file for looking up files in packages that aren't installed. For example:
apt-file list packagename 0 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):
1You 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-fsExample
% dpkg -S /usr/lib/tracker/tracker-store
tracker: /usr/lib/tracker/tracker-storeUsing apt-file:
apt-file search /usr/lib/tracker/tracker-storeor 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-storeOr online here, in the section Search the contents of packages.
Example
2This is an extension to Alexx Roche's excellent answer. I tried to make an edit to that answer, but it got rejected (though not by Alexx)
I was trying to track down what installed which on my system. After a little work I created /usr/local/bin/apt-whatprovides
#!/bin/sh
#apt-whatprovides ver. 201801010101 Copyright alexx, MIT Licence
#rdfa:deps="[realpath,apt-file,grep,which,sh,echo]"
BINARY="$(realpath $(which $@) 2>/dev/null)"
[ -z "$BINARY" ] && BINARY="$@"
echo Searching for $BINARY
PACKAGE="$(apt-file search $BINARY|grep -E ":.*[^-.a-zA-Z0-9]${BINARY}$")"
echo "${PACKAGE}"Though for most THINGs that are installed you can just use:
apt-file search $(realpath $(which THING)) | grep 'THING$'For THINGs that are not installed, you can use:
apt-file search THING | grep '/THING$'The apt-whatprovides script works for files that are and are not on your system. For example, my system lacked dig but had ping so this it what resulted:
pi@raspberrypi:~ $ apt-whatprovides ping
Searching for /bin/ping
inetutils-ping: /bin/ping
iputils-ping: /bin/ping
pi@raspberrypi:~ $ apt-whatprovides dig
Searching for dig
dnsutils: /usr/bin/dig
epic4: /usr/share/epic4/script/dig
epic4-help: /usr/share/epic4/help/8_Scripts/dig
knot-dnsutils: /usr/bin/digNotice that Searching for is a complete path for ping (installed) and just the binary name for dig not installed. This helped me discover that I needed to install dnsutils without needing to go search
I was trying to track down what installed which on my system. After a little work I created apt-whatprovides
#!/bin/sh
#apt-whatprovides ver. 201801010101 Copyright alexx, MIT Licence
#rdfa:deps="[realpath,apt-file,grep,which,sh,echo]"
BINARY=$(realpath $(which $@))
PACKAGE=$(apt-file search $BINARY|grep -E ":\s*${BINARY}$")
echo ${PACKAGE%:*}Though for most THINGs you can just use
apt-file search $(realpath $(which THING))|grep 'THING$' 3 One reason you might have to do this is if you are compiling software which there already is an ubuntu package, you can run apt-get build-dep $PACKAGENAME. That will install all packages you need to compile $PACKAGENAME.
You can use apt to do it.
$ apt contains /bin/ls
coreutils: /bin/lsThe output is same as:
$ dpkg -S /bin/ls
coreutils: /bin/ls Why:
Different distro has its own way, too many commands to remember o(╥﹏╥)o
How:
A universal solution: pacapt -Qo file_path
Outcome:
On ubuntu:
$ pacapt -Qo /usr/bin/iostat
sysstat: /usr/bin/iostatOn centos:
$ pacapt -Qo /usr/bin/iostat
sysstat-10.1.5-19.el7.x86_64Even can find path itself:
$ pacapt -Qo iostat
sysstat: /usr/share/man/man1/iostat.1.gz
sysstat: /usr/bin/cifsiostat
sysstat: /usr/bin/iostat
sysstat: /usr/share/man/man1/cifsiostat.1.gzWhat is pacapt:
pacapt is a wrapper for many package managers
Install:
Simply download the portable script:
wget -O $HOME/bin/pacapt