Find which package contains a specific file

Written by
Date: 2011-09-04 08:10:00 00:00

When you are compiling there are times, when you need to install a given library, but the problem is that you do not know which package to install.

I mean you can't install the library itself as it is contained in a given package, you first need to know which package it belongs to. Once you know that, you can install that package and continue with your job.

Let's now see how to do it in some Linux distributions.

Let's start with the most famous Linux distributions

Debian, Ubuntu and derivatives

We'll use apt-file. First install it.

apt-get install apt-file

Update its database:

apt-file update

And now search for a specific file.

apt-file search [file you are looking for]

Arch Linux

If you are using one of my favorite distributions, just use pacman

pacman -Qo [file you are looking for]

Example:

pacman -Qo identify

Returns:

/usr/bin/identify is owned by imagemagick 6.7.1.0-1

You can also use pkgfile similar to the Debian tool, so let's install it:

pacman -S pkgtools

Then just look for the file with:

pkgfile [file you are looking for]

Redhat, Fedora en derivatives

If you are using a Redhat derivative, there is also a solution for you, just use rpm:

rpm -qf [file you are looking for]

[Update] From an email I got, I have been told that this is the real command to be used in *rpm based distributions.

yum provides */[file]