Using the yum (or dnf) provides option

This comes up so frequently on the Fedora forums (and occasionally on the CentOS forums) that I've gotten tired of typing the same thing. Therefore, I've put it here so that I can just type a link whenever the question arises.

Sometimes, if one chooses to compile a package from source on Fedora or other RH based distribution, it will fail with a message such as Xrandr.h not found. Other common missing files are shared object files, such as myfile.so.1. Another common thing is typing a command, and getting an error that the command is not found.

Sometimes, the answer is easy--one sees something like libXft.so.1 not found and realizes that they forgot to install the libXft-devel package. Other times, it's not so simple. (And even the example above won't be obvious without some knowledge and experience).

Yum and dnf have a great tool for solving this issue, the provides option. If I tried to compile dwm, the tiling window manager, and haven't installed libX11-devel I will get an message like Fatal error X11/Xlib.h not found.

I need to know what package provides this file, so I can use the provides option.
yum provides */X11/Xlib.h

The command searches rpm databases, so may take a little while. In the end, however I get back a list of packages that include X11/Xlib.h in the files that they provide, including the one I need, libX11-devel.

This can also be useful when you see a tutorial suggesting you type a command, but can't find the command or what package provides it. For example, one might try typing rpmbuild and get a message that the command is not found. One then tries yum search rpmbuild and gets a message that it can't be found. However, doing yum provides */rpmbuild will show you that one must install the rpm-build package.

One last tip--if it's a common package that you're pretty sure will be in the main repo, you can speed up the search by eliminating the extra repos you have. For example, if one has the chromium repo, rpmfusion repos, and various testing repos enabled, but wants something that they suspect is a pretty basic package, one can tell yum to only search the basic repo. The order here is important, disable all, and then enable one, rather than vice versa.
dnf --disablerepo=* --enablerepo=fedora provides */rpmbuild.

Another way to speed things up is to used cached data with the -C option.
dnf -C provides */libX11.h

If you get an error like Caching enabled and local cache doesn't match checksum, Caching enabled but no local cache for any particular repo, or any other Caching enabled but some problem, this can be fixed with
dnf makecache