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

Find The Package That Provides A Specific File

This brief tutorial explains a few different ways to find the package that provides a specific file in Unix-like operating systems. This could be useful when you manually compile and install a package. When you’re compiling a package from source, there are chances that you may receive an error something like “No rule to make target ‘<somefile>’, needed by ‘<somefile>’. Stop.”. You may not know exactly which packages provides the missing file. In such cases, you can easily find out the packages that provides those missing files and install them as described in this guide.

Find The Package That Provides A Specific File In Linux

Arch Linux, Antergos, 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

RHEL, CentOS, Fedora:

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

yum whatprovides '*filename'

On Fedora, use the following command instead:

dnf provides '*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 APT-based systems, you can find the package that provides a certain file using apt-file tool.

Install apt-file using command 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

Also read:


And, that’s all. Hope this helps. If you know any other methods to find to find the package that contains a particular file, feel free to let us know in the comment section below. We will be posting more useful guides like this in the days to come. Stay tuned!

Cheers!

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...