When working with YUM package management on CentOS/RHEL systems, you might need to determine which repository a particular package was installed from. This becomes particularly important when:
- Debugging dependency conflicts between repositories
- Verifying package sources for security audits
- Maintaining consistent environments across servers
While yum info package-name
shows basic information, it doesn't display the source repository for installed packages. Here's a more effective approach:
# Check available repositories
yum repolist
# Detailed package information including repository
yum info package-name --showduplicates
The most reliable method is to query YUM's database directly:
# For a specific package
yumdb get from_repo package-name
# Example output for httpd:
# from_repo=base
For multiple packages, you can combine commands:
rpm -qa | xargs -n 1 yumdb get from_repo
If you need to check installation history:
# View complete yum history
yum history
# Get details for a specific transaction
yum history info transaction-id
For graphical interfaces, you can use:
yumex
Let's say you're getting dependency errors with PHP packages. Here's how to investigate:
# First identify which PHP versions are installed
rpm -qa | grep php
# Then check each package's source
yumdb get from_repo php-common
yumdb get from_repo php-cli
# Compare with available versions
yum --showduplicates list php-common
For scripted solutions, you can parse YUM's cache directly:
# View raw cache data (XML format)
cat /var/cache/yum/x86_64/7/base/primary.xml.gz | gunzip | grep -A 10 "package-name"
When working with YUM package manager on RHEL/CentOS systems, you might need to identify which repository a particular package was installed from. This becomes crucial when:
- Debugging dependency issues
- Maintaining system consistency
- Auditing package sources
- Resolving repository conflicts
While yum info
and yum list
show installed packages, they don't reveal the source repository. Here's what you typically see:
$ yum info httpd
Installed Packages
Name : httpd
Arch : x86_64
Version : 2.4.6
Release : 97.el7.centos
Size : 3.7 M
Repo : installed
The yumdb
command provides access to YUM's package database, including repository information:
$ yumdb get from_repo httpd
httpd-2.4.6-97.el7.centos.x86_64 from_repo=base
For packages installed in previous transactions, use:
$ yum history info httpd
Transaction ID : 42
Command Line : install httpd
Packages Altered:
Install httpd-2.4.6-97.el7.centos.x86_64 @base
Here's a bash script to check repository sources for all installed packages:
#!/bin/bash
for pkg in $(yum list installed | awk 'NR>1 {print $1}' | cut -d. -f1)
do
repo=$(yumdb get from_repo $pkg 2>/dev/null)
echo "$pkg : $repo"
done
For systems where yumdb isn't available, you can parse the cache:
$ grep -r "httpd-2.4.6" /var/cache/yum/
/var/cache/yum/x86_64/7/base/packages/httpd-2.4.6-97.el7.centos.x86_64.rpm
- Local installations won't show repository info
- Manually installed RPMs won't have from_repo data
- Repository metadata might be outdated
Knowing package origins helps maintain system integrity. For production systems, consider:
- Regularly cleaning yum cache (
yum clean all
) - Documenting repository configurations
- Using version control for repo files