The sources.list file under Debian: role, syntax, etc.

The sources.list file under Debian: role, syntax, etc.

I. Presentation

In this tutorial, we will study and manipulate the “sources.list” file of a machine running Debian or Ubuntu. But by the way, what is the “sources.list” file?

This file located in ” /etc/apt/sources.list is a text document referencing all the sources used by the APT utility to download the packages. By default, repositories are already filled in this file, but you can add other sources (especially in the “/etc/apt/sources.list.d/“). Thanks to the entries added by default, when performing “apt-get install “, one can download and install a package if it is available in the official repositories for the current version of the system. To work, APT needs a list of package sources.

Initial version of the article: October 5, 2011.

II. The syntax of the /etc/apt/sources.list file

The “/etc/apt/sources.list” file is the main repository which the APT manager relies on to download packages. However, it is not the only file used by the system since there are the “/etc/apt/sources.list.d/” directory which also contains other files that can be used to load other sources (making references to additional repositories). This is interesting in order to avoid modifying the main file, although it is sometimes necessary.

Note : The files inside the directory “/etc/apt/sources.list.d/“must use extension”.list“.

Good practice is to use the “/etc/apt/sources.list” file for official repositories and to use the “sources.list.d” directory for other repositories.

On a Debian 11 machine, here is the contents of the /etc/apt/sources.list file:

cat /etc/apt/sources.list

Debian - Fichier sources.list

We can see that this file uses a particular syntax, highlighted on the example above thanks to the different colors. To be more precise, we can determine the syntax of this file as follows:

deb  du dépôt>/<répertoire d'accès> <archive> <composant>

Take this line for example:

deb  bullseye main

We can say that it defines the corresponding packet source at the address ““on the server”ftp.fr.debian.org“, using the archive “bullseye” which is the code name of Debian 11 (we can consider that here we indicate the name of the distribution), and targeting the component “main“.

This line starts with “deb” while other lines begin with “deb-src“. This is the type of archive. Here is the explanation provided on the Debian wiki : “The first word on each line, deb or deb-srcindicates the archive type. Deb indicates that the archive contains binary (deb) packages which are the precompiled packages we generally use. Deb-src indicates the source packages which are the original source Linux programs plus the Debian control file (.dsc) and the diff.gz containing the changes needed to package the program.

For the “archive” field, you should know that:

  • In the case of a Debian 10 machine, we will see “buster” instead of “bullseye“, because that’s the code name of this distro
  • Other values ​​are possible like “oldoldstable“, “oldstable” (previous stable release), “stable“, “testing“, “unstable” (sid)
  • Security updates are distributed through a specific archive: -security
  • To use a package that will be available in the next Debian release (testing) on its current stable distribution, one should target using the syntax “-backports” – This is to know, because in some cases, we have recourse to this method

For the “component” field, you need to know:

  • main : corresponds to all the packages available on this version of Debian, and they are exclusively free packages which respect the principles of Debian
  • contrib : matches free packages, but related to non-free packages
  • non-free : corresponds to non-free packages, i.e. proprietary packages or packages with a strict user license, so we are outside the scope of “free software

Note : a deposit is also called repository in English.

To edit the contents of the sources.list file, you must have “sudo” permissions (or use the “root” account) and use a text editor (nano, vi, etc.).

III. The /etc/apt/sources.list.d/ folder

As I said, the “/etc/apt/sources.list.d” directory may contain other files for the purpose of declaring unofficial repositories, i.e. not related to Debian directly , but which allow you to retrieve packages for Debian. This is the case of CrowdSec, Docker, etc…

For example, to install CrowdSec on Debian, we add the following file:

/etc/apt/sources.list.d/crowdsec_crowdsec.list

This file contains the content below, which incorporates the principles mentioned above. However, it should be noted the presence of the GPG key which is used to verify the signature of the packages :

deb [signed-by=/usr/share/keyrings/crowdsec_crowdsec-archive-keyring.gpg]  bullseye main
deb-src [signed-by=/usr/share/keyrings/crowdsec_crowdsec-archive-keyring.gpg]  bullseye main

IV. Update package list

When you add a new repository to the “sources.list” (or in “sources.list.d“), it is important to update the APT manager cache. Otherwise, it will not take into account your new repository or the change you just made to find a package. To do this, run the following command:

sudo apt-get update

Note that the command “apt-get update” will read the main file as well as the “.list” files located in the directory “sources.list.d“.

V. The apt-cache and apt-key commands

Finally, know that there are two additional commands to know to view the current configuration of your machine. First of all, the command below allows you to view the list of declared repositories and the associated priority each time.

apt-cache policy

Debian - apt-cache policy - Exemple

Finally, the command below displays the list of GPG keys declared on your system with several information, including the expiration date and the issuer.

apt-key list

VI. Conclusion

The sources.list file is an essential file under Debian and even if it is not modified every day, it is important to know how it works and to know its role within the system. As you will have understood, it is essential for the proper functioning of the APT package manager.

Commandes et Système,Configuration,Debian,Linux,

#sources.list #file #Debian #role #syntax

Leave a Comment

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