How to find which rpm package provides a specific file or library in RHEL / CentOS

‘The Ask’ here is to find the rpm package from which provides a specific binary like /bin/lvcreate or a library file. There 2 commands which can help you find the rpm package from the file – rpm and yum. You can also find all the files included in a package with the rpm command.

Find rpm package which provides a particular binary file or library file

1. Method 1 : using rpm command

1. Use below rpm commands to find which rpm package provide a particular file.

# rpm -q --whatprovides [file name]

For example, to find which rpm package provides /etc/hosts file, use the command below:

# rpm -q --whatprovides /etc/hosts
setup-2.8.14-23.el6.noarch

To find the rpm package which provides the library file /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgomp.so, use the command below.

# rpm -qf /usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgomp.so
gcc-4.4.7-18.el6.x86_64

Similarly, you can also use the command below command as well.

# rpm -qf [file name]

For example,

# rpm -qf /etc/hosts
setup-2.8.14-23.el6.noarch

Method 2 : Using yum command

Below yum command provides the package which owns/provides the file name. To use yum the system should be registered to RHN or an appropriate repository.

# yum whatprovides [file_name]

For example :
One can use following command to identify the package which provides a particular library file:

# yum whatprovides libstdc++
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
libstdc++-4.8.5-4.el7.x86_64 : GNU Standard C++ Library
Repo        : @repo

or to search for a binary:

# yum whatprovides *bin/ls
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
coreutils-8.22-15.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts
Repo        : @repo
Matched from:
Filename    : /bin/ls
Filename    : /usr/bin/ls

Finding file and libraries provided by a particular package

To find all the files (binaries and library files) provided by a package, use the below command.

# rpm -ql bash
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc
/usr/bin/alias
/usr/bin/bash
/usr/bin/bashbug
/usr/bin/bashbug-64
/usr/bin/bg
Related Post