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?
You can use
dpkg
command to find out which installed package owns a file:From
man dpkg
:Example:
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.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:Then, you need to update it's database:
And, finally, search the file:
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.
There's also apt-file for looking up files in packages that aren't installed. For example:
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
You mean, which package and not which application. The application is your package manager, e.g.
Software Center
.Using
dpkg
:Example
Using
apt-file
:or also possible:
Example
Or online here, in the section
Search the contents of packages
.Example
This 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
Though for most THINGs that are installed you can just use:
For THINGs that are not installed, you can use:
The
apt-whatprovides
script works for files that are and are not on your system. For example, my system lackeddig
but hadping
so this it what resulted:Notice that
Searching for
is a complete path forping
(installed) and just the binary name fordig
not installed. This helped me discover that I needed to installdnsutils
without needing to go search https://packages.ubuntu.com/#search_contentsI was trying to track down what installed
which
on my system. After a little work I created apt-whatprovidesThough for most THINGs you can just use
You can use
apt
to do it.The output is same as:
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
.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:
On centos:
Even can find path itself:
What is pacapt:
Install:
Simply download the portable script:
wget -O $HOME/bin/pacapt https://github.com/icy/pacapt/raw/ng/pacapt