How to Determine Which Package Provides a File – DNF

By | 2023-11-04

There will be times when you will be wanting a particular program, header, or library, but aren’t sure which package it is in. Instead of trying to search the repositories for packages by name and description with dnf search, you can use dnf provides to search the repository for packages that provide a particular file. For example, most distributions don’t install ifconfig by default.

Below is an example of searching the repositories for ifconfig on AlmaLinux 9:

[root@alma9 ~]# dnf provides ifconfig
Last metadata expiration check: 0:10:06 ago on Sat Nov  4 08:39:01 2023.
net-tools-2.0-0.62.20160912git.el9.x86_64 : Basic networking tools
Repo        : baseos
Matched from:
Filename    : /usr/sbin/ifconfig

[root@alma9 ~]# 

As you can see, the file is provided by the net-tools package.

It can’t find it. Now What?

By default, if you don’t provide a full path, dnf provides will automatically try prepending the path with /usr/bin, and then /usr/sbin.

I am currently writing an updated guide on building the latest version of HAProxy from source on AlmaLinux 9. The build system can’t find a file it needs, pcre.h. I try to find the package name with dnf provides pcre.h and get the following results:

[root@alma9-haproxy haproxy-2.8.3]# dnf provides pcre.h
Last metadata expiration check: 0:25:40 ago on Sat Nov  4 09:02:07 2023.
Error: No matches found. If searching for a file, try specifying the full path or using a wildcard prefix ("*/") at the beginning.

Fortunately, dnf provides gave us a hint. If you don’t know the full path and it is not in one of the default locations, you can use wildcards:

[root@alma9-haproxy haproxy-2.8.3]#  dnf provides '*/pcre.h'
Last metadata expiration check: 0:31:31 ago on Sat Nov  4 09:02:07 2023.
mingw32-pcre-8.43-7.el9.noarch : MinGW Windows pcre library
Repo        : crb
Matched from:
Filename    : /usr/i686-w64-mingw32/sys-root/mingw/include/pcre.h

mingw64-pcre-8.43-7.el9.noarch : MinGW Windows pcre library
Repo        : crb
Matched from:
Filename    : /usr/x86_64-w64-mingw32/sys-root/mingw/include/pcre.h

pcre-devel-8.44-3.el9.3.i686 : Development files for pcre
Repo        : appstream
Matched from:
Filename    : /usr/include/pcre.h

pcre-devel-8.44-3.el9.3.x86_64 : Development files for pcre
Repo        : appstream
Matched from:
Filename    : /usr/include/pcre.h

That’s better. I am not cross compiling it for Windows, so pcre-devel is what I need.

I still can’t find it

If you still can’t find it, try enabling some repositories that are disabled by default. The documentation on the AlmaLinux Repositories wiki page should work for most RHEL clones. If you are using RHEL, I would use the subscription-manager tool to maintain the base repositories.

If none of those repositories has it, I would try EPEL next.

You can also try the relevant project website, as sometimes software developers will host their own repositories.

If you still can’t find it, you are probably going to have to do some web searches, asking on forums, or installing it manually or from source.

References

See Also