How to Precisely Verify if a Specific Package is Installed Using YUM in RHEL/CentOS


2 views

When working with YUM package management on RHEL or CentOS systems, many developers fall into the trap of using imprecise methods to check for installed packages. The common approach of grepping through yum list installed or rpm -qa output often yields false positives:

# Problematic approach
yum list installed | grep bind

This returns everything with "bind" in the name, including dependencies and unrelated packages. What we really need is a way to check for specific package installation status.

Here are several accurate ways to verify package installation:

1. Using yum list with Exact Package Name

yum list installed bind

This will only show the exact bind package if installed, with no extra matches.

2. Checking Package Installation Status

rpm -q bind

This RPM query returns either the package version (if installed) or "package bind is not installed".

3. Using repoquery for Advanced Checks

repoquery --installed bind

For systems with yum-utils installed, this provides cleaner output and works with wildcards.

When you need to verify a particular version:

rpm -q bind-9.8.2-0.17.rc1.el6_4.6

Or check if any version is installed:

if rpm -q bind &> /dev/null; then
    echo "Package is installed"
else
    echo "Package is not installed"
fi
  • Don't rely solely on grep patterns - they're too broad
  • Remember that package names are case-sensitive
  • Some packages have different names in different distros
  • Consider architecture suffixes (.x86_64, .noarch)

For reliable scripting, use:

if yum list installed bind &> /dev/null; then
    # Your installation logic here
fi

Or for silent checks:

rpm -q --quiet bind && echo "Installed" || echo "Not installed"

When working with YUM package management on RHEL or CentOS systems, many administrators use commands like:

yum list installed | grep package_name
rpm -qa | grep package_name

However, these methods often return too many results when you're looking for a specific package. For example, when searching for the bind package, you might get:

bind-utils-9.8.2-0.17.rc1.el6_4.5.x86_64
rpcbind-0.2.0-11.el6.x86_64
bind-libs-9.8.2-0.17.rc1.el6_4.5.x86_64
samba-winbind-3.6.9-151.el6.x86_64
samba-winbind-clients-3.6.9-151.el6.x86_64
ypbind-1.20.4-30.el6.x86_64

Method 1: Using YUM List with Exact Package Name

The most precise way to check for a specific package is:

yum list installed package_name

For the bind package example:

yum list installed bind

This will return only the exact package you're looking for, or nothing if it's not installed.

Method 2: Using RPM Query with Exact Name

For even faster checking (bypassing YUM):

rpm -q package_name

Example:

rpm -q bind

Method 3: Checking Package Version and Architecture

If you need to verify a specific version or architecture:

yum list installed package_name.arch

Example:

yum list installed bind.x86_64

Checking Package Files

To verify which files were installed by a package:

rpm -ql package_name

Checking Dependencies

To see what other packages depend on your target package:

yum deplist package_name

Using Wildcards for Partial Matches

When you're not sure of the exact package name:

yum list installed "*partial_name*"

Here's a complete verification sequence for the bind package:

# Check if bind is installed
if yum list installed bind &>/dev/null; then
    echo "bind is installed"
    # Get version information
    rpm -q bind --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n'
    # List installed files
    rpm -ql bind | head -5 # showing first 5 files for brevity
else
    echo "bind is not installed"
fi

1. Case sensitivity - Package names are case sensitive
2. Architecture matters - bind.x86_64 vs bind.i686
3. Version prefixes - Some packages have epoch numbers (like 32: in your example)
4. Repository differences - The same package might have different names in different repos

For systems using DNF (Fedora, newer RHEL/CentOS):

dnf list installed package_name

For comprehensive package information:

yum info package_name