How to find what package a file belongs to on CentOS or Fedora

If you know the name of a package you want, it is straightforward to install the package with a software package manager, such as yum on RedHat-based systems. However, what if all you know is the name of an executable binary or library file that is missing, and you want to install whatever package that provides the file?

In this tutorial, I will explain how to find what package a particular file belongs to on RHEL-based platforms such as CentOS or Fedora.

There are two ways to find out what package contains a specific file on CentOS or Fedora.

Method One

The first method is to use yum command itself. With "whatprovides" option, yum allows you to search for which package provides a requested file. With the option, you can specify the full path to a specific file, or wildcards for multiple files.

$ yum whatprovides /usr/bin/mysqladmin
mysql-5.1.66-2.el6_3.x86_64 : MySQL client programs and shared libraries
Repo        : base
Matched from:
Filename    : /usr/bin/mysqladmin

mysql-5.1.69-1.el6_4.x86_64 : MySQL client programs and shared libraries
Repo        : updates
Matched from:
Filename    : /usr/bin/mysqladmin

mysql-5.1.67-1.el6_3.x86_64 : MySQL client programs and shared libraries
Repo        : updates
Matched from:
Filename    : /usr/bin/mysqladmin

mysql-5.1.69-1.el6_4.x86_64 : MySQL client programs and shared libraries
Repo        : installed
Matched from:
Filename    : /usr/bin/mysqladmin

As you can see above, the mysqladmin command located in /usr/bin is contained in a software package called mysql.

Method Two

The second method is via repoquery, a command-line utility for querying YUM repositories.

To install repoquery on CentOS, Fedora or RHEL:

$ sudo yum install yum-utils

To run repoquery to search for a package that contains a file, use the following format.

$ repoquery --whatprovides '/usr/bin/mysqldump'
mysql-0:5.1.69-1.el6_4.x86_64
mysql-0:5.1.66-2.el6_3.x86_64
mysql-0:5.1.67-1.el6_3.x86_64

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *