How to Find RPM Packages Providing Specific Files (Installed or Available)


4 views

When working with RPM-based Linux distributions like RHEL, CentOS, or Fedora, you often need to identify which package provides a specific file. This becomes crucial when:

  • You encounter "command not found" errors
  • Need to install missing dependencies
  • Want to track package ownership of system files

There are two primary approaches depending on whether the file is already installed:

For installed files:

# Syntax:
rpm -qf /path/to/file

# Example:
$ rpm -qf /bin/ls
coreutils-8.22-24.el7.x86_64

For uninstalled files:

# Syntax:
yum provides */filename

# Example (including wildcards):
$ yum provides */libssl.so.1.1
openssl-libs-1:1.1.1k-5.el9.x86_64 : Libraries from OpenSSL
Repo        : baseos
Matched from:
Filename    : /usr/lib64/libssl.so.1.1

Sometimes you need more sophisticated queries:

1. Searching for partial filenames:

yum provides "*libssl*"

2. Checking across all repositories (including disabled ones):

yum --disablerepo=* --enablerepo=epel provides */htop

3. Using dnf on newer systems (Fedora/RHEL8+):

dnf provides /usr/bin/python3

The yum provides command can be slow as it needs to scan metadata. To speed up repeated queries:

# First build the cache:
yum makecache

# Then perform your query:
yum provides */filename

Imagine you're trying to compile software and get this error:

configure: error: libxml2 not found

Solution steps:

# 1. Find which package provides libxml2
$ yum provides */libxml2.so
libxml2-2.9.7-9.el9.x86_64 : Library providing XML and HTML support
Repo        : baseos
Matched from:
Filename    : /usr/lib64/libxml2.so

# 2. Install the required package
$ sudo yum install libxml2

For some distributions or specific needs:

  • dnf repoquery (more powerful alternative on newer systems)
  • apt-file (Debian/Ubuntu equivalent)
  • zypper wp (openSUSE equivalent)

Remember that exact paths matter - a query for /usr/lib/libssl.so won't match /usr/lib64/libssl.so even if they're functionally equivalent.


When working with RPM-based Linux distributions, you often need to determine which package provides a specific file. The rpm command offers powerful query options for this purpose:

rpm -q --whatprovides /path/to/file       # For installed files
rpm -q --whatprovides 'feature-name'      # For virtual provides

To search beyond just installed packages, you'll need to combine rpm with yum or dnf:

# For installed packages:
rpm -qf /usr/bin/vim

# For available packages (using yum/dnf):
dnf provides /usr/bin/vim
# or
yum whatprovides /usr/bin/vim

Here are some common real-world scenarios:

# Find which package provides a missing library
dnf provides */libssl.so.1.1

# Check virtual provides
rpm -q --whatprovides 'config(php)'

# Wildcard searches
dnf provides "*/xml2-config"

For more complex queries, you can chain commands or use regular expressions:

# Search multiple files
for file in /usr/bin/curl /usr/bin/wget; do
    rpm -qf $file || dnf provides $file
done

# Search with regex
dnf provides "*/python[0-9]\.[0-9]/site-packages"

When working with large systems:

  • rpm -qf is faster but limited to installed packages
  • dnf provides is slower but searches all available repositories
  • Consider rebuilding the RPM database if queries become slow: sudo rpm --rebuilddb