1. Overview

On Linux, we can list installed packages using the command line. However, there might be situations when we only want to check installed packages from a certain repository. A repository refers to a location that contains software packages used for installing and managing applications on Linux.

In this tutorial, we’ll discuss how to list all the installed packages from a specific repository on Linux.

2. Debian-Based Distros

On Debian-based distros such as Ubuntu, all the existing repositories on the machine are stored as archive files in the /var/lib/apt/lists directory by default.

Each file refers to a particular repository and contains a set number of packages. To clarify, these packages are stored as archives in the Package format.

So, let’s first navigate to the /var/lib/apt/lists directory:

$ cd /var/lib/apt/lists

Now, let’s list the repositories that exist on the distro:

$ ls
archive.ubuntu.com_ubuntu_dists_focal-backports_Contents-amd64.lz4
archive.ubuntu.com_ubuntu_dists_focal-backports_main_binary-amd64_Packages
archive.ubuntu.com_ubuntu_dists_focal-backports_main_cnf_Commands-amd64
archive.ubuntu.com_ubuntu_dists_focal-backports_main_i18n_Translation-en
archive.ubuntu.com_ubuntu_dists_focal-backports_multiverse_cnf_Commands-amd64
archive.ubuntu.com_ubuntu_dists_focal-backports_restricted_cnf_Commands-amd64
archive.ubuntu.com_ubuntu_dists_focal-backports_universe_binary-amd64_Packages
archive.ubuntu.com_ubuntu_dists_focal-backports_universe_cnf_Commands-amd64
...

Next, we’ll list installed packages from a particular repository via aptitude:

$ sudo aptitude search -F "%p" "~i ?archive(focal-security) ?section(universe)"
libnode64
nodejs-doc

Above, we specified the target repository using the ?archive and ?section search terms:

  • ?archive specifies the source archive, i.e., focal-security
  • ?section specifies the component, i.e., universe

The search subcommand makes aptitude search for all the packages in the specified repository and lists them in the terminal. Since we used the ~i pattern, short for ?installed, only the installed packages are listed. Moreover, the -F option, short for –display-format, specifies the output format, i.e., %p. This format prints the names of the packages in the terminal.

We obtain the values for ?archive and ?section by combining the apt-cache command with the policy subcommand:

$ apt-cache policy
http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages
release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=multiverse,b=amd64
origin security.ubuntu.com
http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=universe,b=amd64
origin security.ubuntu.com
http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages
release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=restricted,b=amd64
origin security.ubuntu.com
http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
release v=20.04,o=Ubuntu,a=focal-security,n=focal,l=Ubuntu,c=main,b=amd64
origin security.ubuntu.com
...

The apt-cache policy command lists all the existing repositories on the distro with additional information.

The second URL on the list refers to the target repository:

security.ubuntu.com_ubuntu_dists_focal-security_universe_binary-amd64_Packages

We can see two labels named a and c in the line after the URL. Here, we used the value of a, i.e., focal-security as the ?archive value, and the value of c, i.e., universe as the ?section value.

3. Fedora-Based Distros

In the case of Fedora-based distros such as RHEL, we can use the dnf command to list existing repositories:

$ sudo dnf repolist
repo id                       repo name
epel                          Extra Packages for Enterprise Linux 8 - x86_64
fedora                        Fedora 36 - x86_64
fedora-cisco-openh264         Fedora 36 openh264 (From Cisco) - x86_64
fedora-modular                Fedora Modular 36 - x86_64
rpmfusion-free                RPM Fusion for Fedora 36 - Free
rpmfusion-free-updates        RPM Fusion for Fedora 36 - Free - Updates
updates                       Fedora 36 - x86_64 - Updates
updates-modular               Fedora Modular 36 - x86_64 - Updates

The repolist subcommand of dnf lists all the existing repositories on the machine.

Next, let’s combine the dnf and grep commands to list installed packages from a particular repository:

$ sudo dnf list --installed | grep @epel
aalib.x86_64           1.4.0-0.37.rc5.el8        @epel
ark.x86_64             22.04.1-1.el8             @epel
bwm-ng.x86_64          0.6.2-1.el8               @epel
dub.x86_64             1.31.1-3.el8              @epel
hw-probe.noarch        1.6.5-1.el8               @epel
mimetic.x86_64         0.9.8-14.el8              @epel
pcl-doc.noarch         1.11.1-4.el8              @epel
vnstat.x86_64          2.9-2.el8                 @epel

We utilized the grep command to search for the repository with the ID of epel, obtained from the repository list. Then, we used the list subcommand with the –installed option to make dnf list all the installed packages from the particular repository.

Evidently, all the installed packages from the repository are listed in the terminal.

4. CentOS

First, let’s list all the repositories on CentOS using the yum command:

$ sudo yum repolist
repo id                  repo name
!base/8/x86_64           CentOS-8 - Base
!docker-main-repo        Docker main Repository
!epel/x86_64             Extra Packages for Enterprise Linux 8 - x86_64
!extras/8/x86_64         CentOS-8 - Extras
!updates/8/x86_64        CentOS-8 - Updates

Now, there are two methods that we can use to list installed packages from a particular repository on CentOS. Let’s discuss them one by one.

4.1. Combining the yum and grep Commands

In this method, we’ll use a command similar to the one that we used for Fedora-based distros. The only difference is that we’ll replace the dnf command with the yum command to complete the operation:

$ sudo yum list --installed | grep @epel
aalib.x86_64           1.4.0-0.37.rc5.el8        @epel
ark.x86_64             22.04.1-1.el8             @epel
bwm-ng.x86_64          0.6.2-1.el8               @epel
dub.x86_64             1.31.1-3.el8              @epel
hw-probe.noarch        1.6.5-1.el8               @epel
mimetic.x86_64         0.9.8-14.el8              @epel
pcl-doc.noarch         1.11.1-4.el8              @epel
vnstat.x86_64          2.9-2.el8                 @epel

We see that all the installed packages from the repository with the ID of epel are printed to the terminal.

4.2. The yumdb Command

We can also use the yumdb command for this operation, which is part of the yum-utils package. This package isn’t built into CentOS. Hence, the first step is to install it using the yum command:

$ sudo yum install yum-utils

Next, let’s use the yumdb command to list installed packages from a specific repository:

$ sudo yumdb search from_repo epel
aalib.1.4.0-0.37.rc5.el8.x86_64
 from_repo = epel

ark.22.04.1-1.el8.x86_64
 from_repo = epel

bwm-ng.0.6.2-1.el8.x86_64
 from_repo = epel

dub.1.31.1-3.el8.x86_64
 from_repo = epel

hw-probe.1.6.5-1.el8.noarch
 from_repo = epel

mimetic.0.9.8-14.el8.x86_64
 from_repo = epel

pcl-doc.1.11.1-4.el8.noarch
 from_repo = epel

vnstat.2.9-2.el8.x86_64
 from_repo = epel

We used the from_repo subcommand to specify the ID of the repository that we want to search, which is epel in this case. Then, we utilized the search subcommand that makes yumdb search for all the installed packages from the specified repository and list them in the terminal, as we can see above.

5. Arch Linux

In Arch Linux, we can list existing repositories using the pacman command:

$ sudo pacman -Syy
core             148.2 KiB         1656K/s
extra            1956.8 KiB        822K/s
community        4.2 MiB           206K/s
multilib         201.4 KiB         1402K/s

The -Syy option tells pacman to list all the existing repositories on the distro.

Next, we can make use of the paclist command to list installed packages from a specific repository:

$ sudo paclist community
aalib 1.4rc5-17
adns 1.6.0-1
aircrack-ng 1.7-3
apparmor 3.1.6-2
cdrtools 3.02a09-5
grub-theme-vimix 20190605-2
libbluray 1.3.4-1
libratbag 0.17-1
texlive-pictures 2023.66594-19

The paclist command lists all the installed packages from the community repository.

6. openSUSE

If we’re using openSUSE, we can utilize the zypper command to list existing repositories:

$ sudo zypper lr
# | Alias                  | Name
--+---------------------+-----------------------------
1 | repo-non-oss           | openSUSE-leap/15.3-Non-Oss
2 | repo-oss               | openSUSE-leap/15.3-Oss
3 | repo-update            | openSUSE-15.3-Update
4 | repo-update-non-oss    | openSUSE-15.3-Update-Non-Oss

The lr subcommand makes zypper list all the existing repositories on the machine.

In order to list all the installed packages from a certain repository, we can again make use of the zypper command:

$ sudo zypper search -i -r repo-oss
Name               | Summary
--------------------------------------------+-------------------
Apper              | KDE application and package management tool
Google Chrome      | Web Browser
Microsoft Edge     | Web Browser
zisofs-tools       | User tools for zisofs
zypper-aptitude    | aptitude compatibility with zypper

The -r option, short for –repo, enables us to specify a repository, which is repo-oss in this case. Then, we used the search subcommand with the -i option, short for –installed-only, which tells zypper to search for all the installed packages from the specified repository and print them to the terminal, as we can see above.

7. Conclusion

In this article, we discussed some methods that we can use to list installed packages from a specific repository on different Linux distributions. We also went through the process of listing existing repositories on these distros and saw how the data in the repository list helps us to complete the main objective.

2 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.