Sometimes if you have a missing library or a file you know should be available via an rpm but you're not sure which RPM you have to install you have to look up for library or binary file amongs all available installable r[ms on Redhat Linux / CentOS / Fedora or other RPM based distro.
It is really annoying especially, if you try to install an rpm binary and the package does not install due to missing dependency library. Having a missing dependency package could happen, if you use some custom internal prepared repository that is mirroring from original rpm repositories and the RPM Repositories are situated behind a DMZ firewall network (such scenarios are common for corporations and IT companies).
Finding out which file is provided by which package on Debian / Ubuntu and other deb based linux distributions is easy and done via the
# apt-file search filename
Thus if you're a system administrator coming from a Debian GNU / Linux sysadmin realm into the wonderful world of redhats, you will want to have an alternative to apt-file tool. You will be happy to find out that that this tedious task is easily done in RPM based Linux and is integrated straight into yum package manager too.
The command to search which rpm package provides a file is:
# yum whatprovides 'nc'
[root@rhel-linux ~]# yum whatprovides nc
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
2:nmap-ncat-6.40-19.el7.x86_64 : Nmap's Netcat replacement
Repo : base
Matched from:
Provides : nc
2:nmap-ncat-6.40-19.el7.x86_64 : Nmap's Netcat replacement
Repo : @base
Matched from:
Provides : nc
yum whatprovides search_file_name can be also invoked with its shortcut yum provides 'search_file_name'
[root@rhel-server ~]# yum provides '/bin/ls'
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
coreutils-8.22-24.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts
Repo : base
Matched from:
Filename : /bin/lscoreutils-8.22-24.el7_9.2.x86_64 : A set of basic GNU tools commonly used in shell scripts
Repo : updates
Matched from:
Filename : /bin/ls
Here is another example:
[root@rhel-server ~]# yum -q provides '*lesspipe.sh*'
less-458-9.el7.x86_64 : A text file browser similar to more, but better
Repo : base
Matched from:
Filename : /usr/bin/lesspipe.shsource-highlight-3.1.6-6.el7.i686 : Produces a document with syntax highlighting
Repo : base
Matched from:
Filename : /usr/bin/src-hilite-lesspipe.shsource-highlight-3.1.6-6.el7.x86_64 : Produces a document with syntax highlighting
Repo : base
Matched from:
Filename : /usr/bin/src-hilite-lesspipe.shspirv-tools-2019.1-4.el7.x86_64 : API and commands for processing SPIR-V modules
Repo : epel
Matched from:
Filename : /usr/bin/spirv-lesspipe.sh
You can search for any file and if the RPm repository is defined under /etc/yum/repos.d/* and enabled, yum whatprovides command should be able to find it and tell you which RPM package you have to install to have the file installed Redhat way.
- You can list all enabled RPM repositories with cmd:
[root@rhel-server ~]# yum repolist enabled
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
repo id repo name status
3party Third party packages – x86_64 2,631
base/7/x86_64 CentOS-7 – Base 10,072
cr/7/x86_64 CentOS-7 – CR 0
epel/7/x86_64 EPEL packages for RedCent 7 – x86_64 13,791
extras/7/x86_64 CentOS-7 – Extras 526
updates/7/x86_64 CentOS-7 – Updates 5,802
zabbix-6.0 Zabbix 6.0 repo 429
repolist: 33,251
- To list disable RPM repositories:
# yum repolist disabled
…
To list all present available repositories that could be enabled and are set via the /etc/yum.repos.d/* configs
# yum repolist all
…