How to list repository in Linux

In Linux, a repository is a collection of software packages that are available for installation on your system.

Think of it as an app store for Linux systems. Repositories make it easier to find, install and update applications, without having to manually compile the source code.

In this article, we’ll explain how to list the repositories on your Linux system, and how to add new repositories.

List Repositories in Redhat CentOS and Fedora

Yum is a package manager for Redhat and CentOS distributions. It allows you to search, install, update, and remove packages from the repositories.

To list the available repositories, use the following command:

yum repolist

This will show all of the repositories configured on your system and whether they are enabled or not.

For example:

repo id repo name status
base/7/x86_64 CentOS-7 - Base enabled: 5,867
extras/7/x86_64 CentOS-7 - Extras enabled: 394
updates/7/x86_64 CentOS-7 - Updates enabled: 1,567

The “status” column indicates whether the repository is enabled or disabled. If a repository is not enabled, you won’t be able to install packages from it.

See also: Mastering the Linux Command Line — Your Complete Free Training Guide

To view only enabled repositories in YUM, use yum repolist enabled

You can list only disabled yum repositories as well. Use yum repolist disabled

Viewing All Repositories (Enabled and Disabled)

To get a more comprehensive view that includes both enabled and disabled repositories, you can use the following command:

yum repolist all

This will add a “status” column to the output, indicating whether each repository is enabled or disabled.

Getting Detailed Repository Information

For more in-depth information about your configured repositories, you can use the repolist command with the -v flag for verbose output. This will show details such as the repository file location, the repository URL, and the last time metadata was updated.

yum repolist -v

Displaying Information for a Specific Repository

If you need to view detailed information for one or more specific repositories, you can use the yum repoinfo command followed by the repository ID.

yum repoinfo <repository_id>

To see information for all repositories, you can use:

yum repoinfo

You can also get all the repositories from the configuration file.

$ cat /etc/yum.repos.d/*

The /etc/yum.repos.d directory contains all the repositories configured for yum-based systems such as Redhat, CentOS and Fedora.

For example, if you have enabled the epel repository, then you should see a file named epel.repo in the directory.

You can view the contents of each repository configuration file to get more information about it.

List Repositories in Debian and Ubuntu

The Advanced Packaging Tool (APT) is the package manager for Debian and Ubuntu distributions. It allows you to search, install, update and remove packages from the repositories. To list the available repositories on your system, use the following command:

apt-cache policy

This will show all of the repositories configured on your system and whether they are enabled or not.

For example:

Package files:
100 /var/lib/dpkg/status
release a=now
500 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
release v=16.04,o=Ubuntu

Or you can get all the repositories from the configuration file.

$ cat /etc/apt/sources.list /etc/apt/sources.list.d/*

The /etc/apt/sources.list is a text file that contains all of the repository locations that have been registered on your system.

The /etc/apt/sources.list.d directory contains files that specify additional repositories to be used by APT. This is a convenient way to add new repositories, without having to edit the main sources.list file.

Here is one example of my system.
$ grep ^[^#] /etc/apt/sources.list /etc/apt/sources.list.d/*
/etc/apt/sources.list:deb <http://us.archive.ubuntu.com/ubuntu/> bionic main restricted
/etc/apt/sources.list:deb <http://us.archive.ubuntu.com/ubuntu/> bionic-updates main restricted
/etc/apt/sources.list:deb <http://us.archive.ubuntu.com/ubuntu/> bionic universe
/etc/apt/sources.list:deb <http://us.archive.ubuntu.com/ubuntu/> bionic-updates universe
/etc/apt/sources.list:deb <http://us.archive.ubuntu.com/ubuntu/> bionic multiverse
/etc/apt/sources.list:deb <http://us.archive.ubuntu.com/ubuntu/> bionic-updates multiverse

Add New Repositories in Linux

You can add new repositories to your system by adding the repository URL to the appropriate configuration file.

For example, on Redhat/CentOS systems, you can add a new repository in the /etc/yum.repos.d/ directory by creating a new file with the .repo extension.

For example, to add the EPEL repository:

$ touch /etc/yum.repos.d/epel.repo

And then add the repository URL to the file. For more detailed info, you can check this article from Redhat.

For Debian/Ubuntu systems, you can add a new repository in the /etc/apt/sources.list file by adding a line with the URL of the repository.

The URL can usually be found on the website of the software provider (e.g., for Ubuntu, it would be http://us.archive.ubuntu.com/ubuntu/).

Once you have the URL, open the /etc/apt/sources.list file in a text editor (e.g., Nano or Vim) and add the URL to the end of the file, like so:

deb http://us.archive.ubuntu.com/ubuntu/ bionic main

Save your changes and exit the text editor, then run sudo apt update to refresh the repositories. You should now find that the new repository has been added successfully and is available for use.

Conclusion

Listing and adding repositories in Linux is a relatively straightforward process, once you know what tool to use. By following the steps above, you should have no trouble managing your system’s repositories. If in doubt, however, remember to consult the documentation of your Linux distribution for more information.

David Cao
David Cao

David is a Cloud & DevOps Enthusiast. He has years of experience as a Linux engineer. He had working experience in AMD, EMC. He likes Linux, Python, bash, and more. He is a technical blogger and a Software Engineer. He enjoys sharing his learning and contributing to open-source.

Articles: 548

Leave a Reply

Your email address will not be published. Required fields are marked *