Linux which package provides file

How To Find The Package That Provides A File (Installed Or Not) On Ubuntu, Debian Or Linux Mint

1. Using apt-file to find the package that provides a file (for repository packages, either installed or not installed)

apt-file indexes the contents of all packages available in your repositories, and allows you to search for files in all these packages.

That means you can use apt-file to search for files inside DEB packages that are installed on your system, as well as packages that are not installed on your Debian (and Debian-based Linux distributions, like Ubuntu) machine, but are available to install from the repositories. This is useful in case you want to find what package contains a file that you need to compile some program, etc.

apt-file cannot find the package that provides a file in case you downloaded a DEB package and installed it, without using a repository. The package needs to be available in the repositories for apt-file to be able to find it.

apt-file may not be installed on your system. To install it in Debian, Ubuntu, Linux Mint and other Debian-based or Ubuntu-based Linux distributions, use this command:

This tool find the files belonging to a package by using a database, which needs to be updated in order to be able to use it. To update the apt-file database, use:

Now you can use apt-file to find the DEB package that provides a file, be it a package you’ve installed from the repositories, or a package available in the repositories, but not installed on your Debian / Ubuntu / Linux Mint system. To do this, run:

Replacing filename with the name of the file you want to find.

This command will list all occurrences of filename found in various packages. If you know the exact file path and filename, you can get the search results to only list the package that includes that exact file, like this:

apt-file search /path/to/filename

For example, running only apt-file search cairo.h will list a large list search results:

$ apt-file search cairo.h fltk1.3-doc: /usr/share/doc/fltk1.3-doc/HTML/group__group__cairo.html ggobi: /usr/include/ggobi/ggobi-renderer-cairo.h glabels-dev: /usr/include/libglbarcode-3.0/libglbarcode/lgl-barcode-render-to-cairo.h glabels-dev: /usr/share/gtk-doc/html/libglbarcode-3.0/libglbarcode-3.0-lgl-barcode-render-to-cairo.html gstreamer1.0-plugins-good-doc: /usr/share/gtk-doc/html/gst-plugins-good-plugins-1.0/gst-plugins-good-plugins-plugin-cairo.html guile-cairo-dev: /usr/include/guile-cairo/guile-cairo.h guitarix-doc: /usr/share/doc/guitarix-doc/namespacegx__cairo.html ipe: /usr/share/ipe/7.2.7/doc/group__cairo.html libcairo-ocaml-dev: /usr/share/doc/libcairo-ocaml-dev/html/Pango_cairo.html libcairo-ocaml-dev: /usr/share/doc/libcairo-ocaml-dev/html/type_Pango_cairo.html libcairo2-dev: /usr/include/cairo/cairo.h . 

However, if you know the file path, e.g. you want to find out to which package the file /usr/include/cairo/cairo.h belongs to, run:

apt-file search /usr/include/cairo/cairo.h

This only lists the package that contains this file:

$ apt-file search /usr/include/cairo/cairo.h libcairo2-dev: /usr/include/cairo/cairo.h

In this example, the package that includes the file I searched for ( /usr/include/cairo/cairo.h ) is libcairo2-dev .

Читайте также:  Linux add existing user to groups

apt-file may also be used to list all the files included in a package ( apt-file list packagename ), perform regex search, and more. Consult its man page ( man apt-file ) and help for more information ( apt-file —help ).

2. Using dpkg to find the package that provides a file (only for installed DEB packages — from any source)

dpkg can also be used to find out to which package a file belongs to. It can be faster to use than apt-file, because you don’t need to install anything, and there’s no database to update.

However, dpkg can only search for files belonging to installed packages, so if you’re searching for a file in a package that’s not installed on your system, use apt-file. On the other hand, dpkg can be used to find files belonging to packages that were installed without using a repository, a feature that’s not available for apt-file.

To use dpkg to find the installed DEB package that provides a file, run it with the -S (or —search ) flag, followed by the filename (or pattern) you want to see to which package it belongs, like this:

For example, to find out to which package the cairo.h file belongs to, use dpkg -S cairo.h :

$ dpkg -S cairo.h libgtk2.0-dev:amd64: /usr/include/gtk-2.0/gdk/gdkcairo.h libcairo2-dev:amd64: /usr/include/cairo/cairo.h libpango1.0-dev: /usr/include/pango-1.0/pango/pangocairo.h libgtk-3-dev:amd64: /usr/include/gtk-3.0/gdk/gdkcairo.h

Just like for apt-file, this may show multiple packages that have files containing the filename you’re looking for. You can enter the full path of the file to get only the package that contains that specific file. Example:

$ dpkg -S /usr/include/cairo/cairo.h libcairo2-dev:amd64: /usr/include/cairo/cairo.h

In this example, the Debian package that includes the file I searched for ( /usr/include/cairo/cairo.h ) is libcairo2-dev .

Other notable ways of finding the package a file belongs to is using the online search provided by Ubuntu and Debian:

  • Ubuntu: https://packages.ubuntu.com/ — scroll down to Search the contents o packages and enter the filename you’re looking for, as well as the distribution (Ubuntu version) and architecture.
  • Debian: https://www.debian.org/distrib/packages#search_contents — the search is similar to the one available for Ubuntu, so enter the filename you want to find, the distribution and architecture.

The Linux Mint package search website doesn’t include an option to search for files inside packages, but you can use the Ubuntu or Debian online package search for packages that Linux Mint imports from Debian / Ubuntu.

Источник

How do I find which rpm package supplies a file I’m looking for?

As an example, I am looking for a mod_files.sh file which presumably would come with the php-devel package. I guessed that yum would install the mod_files.sh file with the php-devel x86_64 5.1.6-23.2.el5_3 package, but the file appears to not to be installed on my filesystem. How do I find out which package installs a specific file? I’m looking for where I have not necessarily already locally downloaded the package which may include the file that I’m looking for. I’m using CentOS 5.

Читайте также:  Linux чем отличается от виндовс

@SamWatkins that answer will only work if the package that supplies the file you’re looking for is already installed on the system. If the package is not installed (as the OP says) then you can’t use rpm , you need to use yum .

7 Answers 7

This is an old question, but the current answers are incorrect 🙂

Use yum whatprovides, with the absolute path to the file you want (which may be wildcarded). For example:

grep-2.5.1-55.el5.x86_64 : The GNU versions of grep pattern matching utilities. Repo : base Matched from: Filename : /bin/grep 

You may prefer the output and speed of the repoquery tool, available in the yum-utils package.

sudo yum install yum-utils repoquery --whatprovides '*bin/grep' grep-0:2.5.1-55.el5.x86_64 grep-0:2.5.1-55.el5.x86_64 

repoquery can do other queries such as listing package contents, dependencies, reverse-dependencies, etc.

To know the package owning (or providing) an already installed file:

this command looks to be more efficient than yum whatprovides—no need to get updates from possibly slow repositories.

It seems to me that rpm -qf is best suited for determining which package provides an installed application (since it may be different than what is in the current yum repository cache), and yum whatprovides is best suited for determining which package provides a yet-to-be-installed application. Each has their own purpose.

Furthermore, yum whatprovides . only requires root if the application is a root package (i.e. it resides in /sbin ). However, rpm -qf . also requires root in order to read rpms from /sbin . Therefore, I propose that the root requirements are functionally equivalent for both methods.

Anyone using this command, please note that you have to use full file path + filename, and not just the file name.

The most popular answer is incomplete:

Since this search will generally be performed only for files from installed packages, yum whatprovides is made blisteringly fast by disabling all external repos (the implicit «installed» repo can’t be disabled).

yum --disablerepo=* whatprovides

In this case, however, the OP is specifically looking for a missing file that was not installed on the system, even after installing a package he thought would have it, so he can’t use —disablerepo=*

You go to http://www.rpmfind.net and search for the file.

You’ll get results for a lot of different distros and versions, but quite likely Fedora and/or CentOS will pop up too and you’ll know the package name to install with yum

@jww Searching for files works fine for me at least. As the docs says, you can search for executables by their single path name or any file with the absolute path name.

Читайте также:  Linux параллельное выполнение команд

Well finding the package when you are connected to internet (repository) is easy however when you only have access to RPM packages inside Redhat or Centos DVD (this happens frequently to me when I have to recover a server and I need an application) I recommend using the commands below which is completely independent of internet and repositories. (supposably you have lots of uninstalled packages in a DVD). Let’s say you have mounted Package folder in ~/cent_os_dvd and you are looking for a package that provides «semanage» then you can run:

for file in `find ~/cent_os_dvd/ -iname '*.rpm'`; do rpm -qlp $file |grep '.*bin/semanage'; if [ $? -eq 0 ]; then echo "is in";echo $file ; fi; done 

Using only the rpm utility, this should work in any OS that has rpm:

rpm -q --whatprovides [file name] 

You can do this alike here but with your package. In my case, it was lsb_release

Run: yum whatprovides lsb_release

redhat-lsb-core-4.1-24.el7.i686 : LSB Core module support Repo : rhel-7-server-rpms Matched from: Filename : /usr/bin/lsb_release redhat-lsb-core-4.1-24.el7.x86_64 : LSB Core module support Repo : rhel-7-server-rpms Matched from: Filename : /usr/bin/lsb_release redhat-lsb-core-4.1-27.el7.i686 : LSB Core module support Repo : rhel-7-server-rpms Matched from: Filename : /usr/bin/lsb_release redhat-lsb-core-4.1-27.el7.x86_64 : LSB Core module support Repo : rhel-7-server-rpms Matched from: Filename : /usr/bin/lsb_release` 

Run to install: yum install redhat-lsb-core

The package name SHOULD be without number and system type so yum packager can choose what is best for him.

Источник

How do I find out which package owns a file?

Alternatively, there are several utilites in Debian which perform this task; check this page for a description. I’ll mention two of them, apt-file and dlocate .

apt-file searches its internal cache, thus allowing you to not install all the packages you want to search. Below you will find more detailed guide.

dlocate is a fast alternative to dpkg -L (the command that lists package contents), and as so, it searches only installed packages. Search is performed by dlocate -S file.name .

Also you can search packages online using packages.debian.org server (the Search the contents of packages section).

Installing and using apt-file

It’s a good idea to update first:

sudo apt-get install apt-file 

Read data from repositories (this works also without sudo but creates user’s cache then; with sudo the cache is system-wide):

Perform search. In this example we want to know in which package xrandr executable is:

It lists many packages with unxrandr , lxrandr.mo or source_lxrandr.py . Not very useful in our case. More clever search:

( $ denotes end of line). Example output:

bash-completion: /usr/share/bash-completion/completions/xrandr x11-xserver-utils: /usr/bin/xrandr 

The first result doesn’t look like executable, the second one does. We can investigate further. Run:

apt-cache show x11-xserver-utils 

Bingo! This is the package.

Источник

Оцените статью
Adblock
detector