How to list installed packages from a given repo using yum

Learn how to list installed packages from a given repo using yum with practical examples, diagrams, and best practices. Covers centos, fedora, yum development techniques with visual explanations.

How to List Installed Packages from a Specific YUM Repository

A server rack with glowing lights, symbolizing package management and system administration.

Learn to effectively query and list packages installed on your CentOS or Fedora system that originated from a particular YUM repository. This guide covers essential yum and dnf commands and practical examples.

Managing packages is a fundamental task for any system administrator or developer working with CentOS or Fedora. While yum (and its successor dnf) provides robust tools for installing, updating, and removing software, sometimes you need to identify which packages on your system came from a specific repository. This can be crucial for auditing, troubleshooting, or ensuring compliance with specific software sources. This article will guide you through the commands and techniques to achieve this, providing clear examples and explanations.

Understanding YUM/DNF Repository Metadata

When you install a package using yum or dnf, the package manager records metadata about that installation, including the repository from which the package originated. This information is stored in the RPM database and can be queried using various tools. The key is to leverage yum or dnf's powerful querying capabilities, often in conjunction with repoquery or by directly inspecting RPM package information.

flowchart TD
    A[Start: Need to list packages from a specific repo]
    B{Is `repoquery` installed?}
    B -- Yes --> C[Use `repoquery --installed --repoid=<repo_id>`]
    B -- No --> D[Install `yum-utils` (or `dnf-plugins-core`)]
    D --> C
    C --> E[Review output]
    E --> F[End: List of packages obtained]

Workflow for listing packages from a specific YUM/DNF repository.

The repoquery command, part of the yum-utils package (or dnf-plugins-core for DNF), is specifically designed for querying repository metadata. It's the most straightforward and powerful way to achieve our goal. If you don't have it installed, you'll need to install the respective utilities package first.

# For CentOS/RHEL 7 (YUM)
sudo yum install yum-utils

# For CentOS/RHEL 8+/Fedora (DNF)
sudo dnf install dnf-plugins-core

Install yum-utils or dnf-plugins-core if repoquery is not found.

Once repoquery is available, you can use the --installed flag to filter for installed packages and --repoid=<repo_id> to specify the repository. First, you need to know the exact ID of the repository you're interested in. You can list all enabled repositories with yum repolist or dnf repolist.

# List all enabled repositories to find the repo ID
yum repolist
# OR
dnf repolist

Example output of yum repolist showing repository IDs.

Look for the 'Repo ID' column in the output. For example, if you want to list packages from the epel repository, its ID would typically be epel.

# Using yum-repoquery
repoquery --installed --repoid=epel

# Using dnf-repoquery
dnf repoquery --installed --repoid=epel

Listing installed packages from the 'epel' repository using repoquery.

Method 2: Using yum list installed or dnf list installed with grep

While less precise than repoquery, you can often infer the origin of a package by combining yum list installed or dnf list installed with grep. This method relies on the fact that the repository ID is often appended to the package version or listed in a separate column. This is particularly useful if repoquery is not available and you cannot install it.

# For YUM
yum list installed | grep '@epel'

# For DNF
dnf list installed | grep '@epel'

Listing installed packages from 'epel' using yum/dnf list installed and grep.

Method 3: Inspecting Individual RPM Package Information

For a single package, you can check its origin using rpm -qi <package_name>. The output will include a 'From repo' or 'Source RPM' field that indicates the repository or source package. This is useful for verifying the origin of a specific package.

rpm -qi httpd

Inspecting the origin of the httpd package.

In the output, look for lines like From repo : base or From repo : epel to identify the repository. This method is not practical for listing all packages from a repository but is excellent for individual verification.