How to list installed packages from a given repo using yum
Categories:
How to List Installed Packages from a Specific YUM Repository
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.
Method 1: Using repoquery
(Recommended)
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
.
repoquery
can be extensive. You might want to pipe it to grep
to search for specific packages or wc -l
to count them. For example: repoquery --installed --repoid=epel | grep 'php'
.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
.
@repo_id
suffix might not always be present or consistent for all packages or repositories. repoquery
directly queries the RPM database for the origin, making it more accurate.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.
dnf
is the modern replacement for yum
in Fedora and recent CentOS/RHEL versions. While many yum
commands still work as aliases, it's good practice to use dnf
on newer systems.