[centos] How do I find which rpm package supplies a file I'm looking for?

As an example, I am looking for a mod_files.sh file which presumably would come with the php-devel package. I guessed that yum would install the mod_files.sh file with the php-devel x86_64 5.1.6-23.2.el5_3 package, but the file appears to not to be installed on my filesystem.

How do I find out which package installs a specific file? I'm looking for where I have not necessarily already locally downloaded the package which may include the file that I'm looking for.

I'm using CentOS 5.

This question is related to centos rpm yum

The answer is


To know the package owning (or providing) an already installed file:

rpm -qf myfilename

Well finding the package when you are connected to internet (repository) is easy however when you only have access to RPM packages inside Redhat or Centos DVD (this happens frequently to me when I have to recover a server and I need an application) I recommend using the commands below which is completely independent of internet and repositories. (supposably you have lots of uninstalled packages in a DVD). Let's say you have mounted Package folder in ~/cent_os_dvd and you are looking for a package that provides "semanage" then you can run:

for file in `find ~/cent_os_dvd/ -iname '*.rpm'`;  do rpm -qlp $file |grep '.*bin/semanage';  if [ $? -eq 0 ]; then echo "is in";echo $file  ; fi;  done

This is an old question, but the current answers are incorrect :)

Use yum whatprovides, with the absolute path to the file you want (which may be wildcarded). For example:

yum whatprovides '*bin/grep'

Returns

grep-2.5.1-55.el5.x86_64 : The GNU versions of grep pattern matching utilities.
Repo        : base
Matched from:
Filename    : /bin/grep

You may prefer the output and speed of the repoquery tool, available in the yum-utils package.

sudo yum install yum-utils
repoquery --whatprovides '*bin/grep'
grep-0:2.5.1-55.el5.x86_64
grep-0:2.5.1-55.el5.x86_64

repoquery can do other queries such as listing package contents, dependencies, reverse-dependencies, etc.


The most popular answer is incomplete:

Since this search will generally be performed only for files from installed packages, yum whatprovides is made blisteringly fast by disabling all external repos (the implicit "installed" repo can't be disabled).

yum --disablerepo=* whatprovides <file>

Using only the rpm utility, this should work in any OS that has rpm:

rpm -q --whatprovides [file name]

Ref. https://www.thegeekdiary.com/how-to-find-which-rpm-package-provides-a-specific-file-or-library-in-rhel-centos/


You go to http://www.rpmfind.net and search for the file.

You'll get results for a lot of different distros and versions, but quite likely Fedora and/or CentOS will pop up too and you'll know the package name to install with yum


You can do this alike here but with your package. In my case, it was lsb_release

Run: yum whatprovides lsb_release

Response:

redhat-lsb-core-4.1-24.el7.i686 : LSB Core module support
Repo        : rhel-7-server-rpms
Matched from:
Filename    : /usr/bin/lsb_release

redhat-lsb-core-4.1-24.el7.x86_64 : LSB Core module support
Repo        : rhel-7-server-rpms
Matched from:
Filename    : /usr/bin/lsb_release

redhat-lsb-core-4.1-27.el7.i686 : LSB Core module support
Repo        : rhel-7-server-rpms
Matched from:
Filename    : /usr/bin/lsb_release

redhat-lsb-core-4.1-27.el7.x86_64 : LSB Core module support
Repo        : rhel-7-server-rpms
Matched from:
Filename    : /usr/bin/lsb_release`

Run to install: yum install redhat-lsb-core

The package name SHOULD be without number and system type so yum packager can choose what is best for him.


Examples related to centos

How to uninstall an older PHP version from centOS7 Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details pip install - locale.Error: unsupported locale setting ssh : Permission denied (publickey,gssapi-with-mic) How to change the MySQL root account password on CentOS7? Completely remove MariaDB or MySQL from CentOS 7 or RHEL 7 ffprobe or avprobe not found. Please install one How to check all versions of python installed on osx and centos Cannot find java. Please use the --jdkhome switch VirtualBox: mount.vboxsf: mounting failed with the error: No such device

Examples related to rpm

yum error "Cannot retrieve metalink for repository: epel. Please verify its path and try again" updating ContextBroker How do I extract the contents of an rpm? How to ignore conflicts in rpm installs How to make rpm auto install dependencies setup.py examples? Determining the path that a yum package installed to How do I find which rpm package supplies a file I'm looking for? What is the minimum I have to do to create an RPM file? How to list the contents of a package using YUM?

Examples related to yum

How to Install gcc 5.3 with yum on CentOS 7.2? Completely remove MariaDB or MySQL from CentOS 7 or RHEL 7 RHEL 6 - how to install 'GLIBC_2.14' or 'GLIBC_2.15'? CentOS 7 and Puppet unable to install nc How to yum install Node.JS on Amazon Linux yum error "Cannot retrieve metalink for repository: epel. Please verify its path and try again" updating ContextBroker How to install latest version of git on CentOS 7.x/6.x Upgrading PHP on CentOS 6.5 (Final) Yum fails with - There are no enabled repos. Why does configure say no C compiler found when GCC is installed?