fbpx Linux Repositories: How to Add and Manage with apt and yum | Certificação Linux

Managing Linux Repositories: Add, Remove, and Update Sources

📅 12/02/2021 ⏱ 6 min ✍️ Uira Ribeiro
Linux
Managing Linux Repositories: Add, Remove, and Update Sources
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

Regardless of the distribution you use, you may need to install a new software repository to install a specific package that is not part of the distribution's software repository.

When this happens, the software manufacturer usually provides the URL of their repository for different distributions, so that it can be installed. You must choose the correct URL, according to the Linux distribution used.

Repositories in Debian/Ubuntu

The software installation tool suite in Debian-based distributions uses the software repositories indicated in the file /etc/apt/sources.list and also in the directory /etc/apt/sources.list.d.

By default, each Linux distribution maintains its own software repository, indicating in this file where Linux should look for the packages that the distribution maintains.

That said, it is perfectly possible to add other third-party software repositories, or even change the default repository to a "beta" testing software repository.

On Ubuntu, the sources.list file has the following content:

$ cat sources.list | grep -v "#"deb http://security.ubuntu.com/ubuntu eoan-security main restricteddeb http://security.ubuntu.com/ubuntu eoan-security universedeb http://security.ubuntu.com/ubuntu eoan-security multiverse

The first word "deb" indicates that these are binary software packages, and the word "deb-src" indicates that they are source code packages.

Immediately after, you must indicate the complete URL of the repository, indicating the access protocol: http, https, or ftp.

Then follows the distribution name. In the case of Debian, this can be the version code name (jessie, stretch, buster, sid) or the version class (oldstable, stable, testing, unstable) respectively.

Finally, the component is indicated, which determines the type of software:

  • MAIN: Contains all packages that are fully compliant with the Debian Free Software Guidelines.
  • CONTRIB: Is a set of open-source programs that cannot function without a non-free element.
  • NON-FREE: Contains programs which are not (fully) compliant with these free software principles, but which can nonetheless be distributed without restrictions. 
  • UPDATES: This repository receives package updates, with fixes and improvements.
  • BACKPORTS: The backports repository offers "backported packages". The term refers to a package of some recent software, which has been recompiled for an older distribution, usually for Stable. 
  • SECURITY: Security updates are not hosted on the usual Debian mirror network, but on security.debian.org.
  • PROPOSED-UPDATES: after publication, the stable distribution is updated approximately every two months. The proposed-updates repository is where expected updates are prepared (under the supervision of stable release managers). 
  • DEBIAN MULTIMEDIA: Provides packages for video, image editing, and codecs, among others.

This list of components may vary depending on the Linux distribution.

Adding a repository

To add a repository, simply include a line with the syntax below in the sources.list file:

deb https://servidor/caminho distribuição componente

After configuring a repository in the sources.list file, it is necessary to execute one of the commands from the apt tool suite of your choice, so that the package list from the repository is downloaded, and the repository is incorporated into the system:

$ apt-get update

Or

$ aptitude update

Or

$ apt update

The same command needs to be executed if a repository is removed from the system.

Repositories in Red Hat/CentOS (Yum)

YUM also allows software repositories to be customized in the configuration file yum.conf.

Example of /etc/yum.conf

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
distroverpkg=centos-release

[fedora-us-3-core]

name=Fedora Core 3 — Fedora US mirror baseurl=http://SERVERNAME/fedora/fedora/$releasever/$basearch/RPMS.os

[fedora-us-3-updates]

name=Fedora Core 3 Updates — Fedora US mirror baseurl=http://SERVERNAME/fedora/fedora/$releasever/$basearch/RPMS.updates

In addition to the configuration file /etc/yum.conf, YUM allows you to place repository configuration files in the directory /etc/yum.repos.d/. The configurations for each repository are in this directory.

The files in this directory have the ".repo" extension.

$ ls -l /etc/yum.repos.d/
-rw-r--r--. 1 root root 1664 Ago 13  2018 CentOS-Base.repo
-rw-r--r--. 1 root root  630 Ago 13  2018 CentOS-Media.repo

You can add extra or "beta-test" software repositories to the YUM repository list.

A repository file generally has a name and points to a URL on the Internet. See the CentOS-Base.repo file:

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

After adding a new repository in Yum, the updateinfo command updates the available packages in the repositories:

$ yum updateinfoPlugins carregados: extras_suggestions, langpacks, priorities, update-motdamzn2-core/2/aarch64                                                                                                                                | 2.4 kB  00:00:00     amzn2extra-docker/2/aarch64                                                                                                                         | 1.8 kB  00:00:00     amzn2extra-php7.3/2/aarch64                                                                                                                         | 1.8 kB  00:00:00     Updates Information Summary: updatesupdateinfo summary done

Conclusion

The installation of third-party packages can be done through repository management on Linux.

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp