Home Linux Tips & Tricks How To Find The Package That Provides A Specific File In Linux

How To Find The Package That Provides A Specific File In Linux

By sk
Published: Updated: 58K views

This brief tutorial explains a few different ways to find the package that provides a specific file in Linux. This could be useful when you manually compile and install a package. When compiling a package from source, there's a chance you may receive an error like: "No rule to make target '<somefile>', needed by '<somefile>'. Stop.".

In such cases, you may not know which package provides the missing file. This guide describes how you can easily find out the packages that provide those missing files and install them on your Linux system.

Find the Package that Provides a Specific File in Linux

Arch Linux, EndeavourOS, Manjaro Linux:

On Arch-based, there is a small command line tool called pkgfile, which is used to search files from packages.

Pkgfile comes pre-installed with Arch Linux. If it's not, you can install using the following command:

$ sudo pacman -S pkgfile

Then, run the following command to sync with pkgfile database:

$ sudo pkgfile -u

Now, you can find the package that provides a specific file, say for example alisp.h, using command:

$ pkgfile alisp.h
extra/alsa-lib

As you see in the above output, alsa-lib package provides alisp.h file. And, the package is available from extra repository. You can now install this package as shown below.

$ sudo pacman -S alsa-lib

To list all files provided by the alsa-lib package, run:

$ pkgfile -l alsa-lib

Fedora, RHEL, CentOS, AlmaLinux, Rocky Linux:

In RPM-based systems such as Fedora, RHEL and its clones like CentOS, AlmaLinux and Rocky Linux, you can find the package that owning a particular file, using the following command:

$ dnf provides '*filename'

Or,

$ yum whatprovides '*filename'

If the file is already available in your system, say for example /bin/ls, you can then find the package that owns the file using command:

# rpm -qf /bin/ls
coreutils-8.22-18.el7.x86_64

You can also use the repoquery command as follows:

$ repoquery -f /bin/ls

If repoquery command is not available in your system, install yum-utils package.

$ sudo yum install yum-utils

Or,

$ sudo dnf install yum-utils

Debian, Ubuntu, Linux Mint:

In any DEB-based systems, you can find the package that provides a certain file using apt-file tool.

Install apt-file as shown below if it's not installed already:

$ sudo apt-get install apt-file

If you just installed apt-file, the system-wide cache might be empty. You need to run 'apt-file update' as root to update the cache. You can also run 'apt-file update' as normal user to use a cache in the user's home directory.

Let us update the database cache using command:

$ sudo apt-file update

And, then search for the packages that contains a specific file, say alisp.h, with command:

$ apt-file find alisp.h

Or,

$ apt-file search alisp.h

Sample would be:

libasound2-dev: /usr/include/alsa/alisp.h

Well, libasound2-dev it is! You can install this package using command:

$ sudo apt-get install libasound2-dev

If you already have the file, and just wanted to know which package it belongs to, you can use dpkg command as shown below.

$ dpkg -S $(which alisp.h)

Or,

$ dpkg -S `which alisp.h`

If you know the full path of the file, say for example /bin/ls,  you can search for the packages it belongs to using the following command:

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

SUSE / openSUSE:

On SUSE and openSUSE, run the following command to find out which package a certain file belongs to.

$ zypper wp alisp.h

Or,

$ zypper se --provides --match-exact alisp.h

And, that's all. Hope this helps. If you know any other methods to find the package that contains a particular file, feel free to let us know in the comment section below. I will check and update the guide accordingly.

You May Also Like

1 comment

Cilyan Olowen August 17, 2020 - 3:08 pm

On Arch based distros, pacman -Qo will also show the package the file is from, without the need to install an extra tool.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More