Debian

Understanding and Using Debian sources.list

In Linux, the repository is a storage location hosted on remote servers from which the system retrieves and installs software and updates. In our systems, these repositories are listed in the /etc/apt/sources.list file and in the files under the /etc/apt/sources.list.d/ directory. This file and directory already contain some essential software repositories, known as standard repositories, but you may add other software repositories, as well. However, while adding the repositories in the sources.list file, you must know what each entry in the file means. This article will help you understand what the sources.list file is and how to use it to add repositories in the Debian system.

The commands and procedure discussed in this article have been tested in a Debian 10 Buster system.

Understanding the sources.list File

The /etc/apt/sources.list file looks like this:

This file contains the list of default sources for installing software on your system. In the /etc/apt/sources.list file above, you will see some lines starting with the “#” symbol. These are comments used to disable the repository or to add an explanation about the source. All the lines in this file are listed in a particular format.

Next, you will learn more about the content of the /etc/apt/sources.list file.

The /etc/apt/sources.list file contains the sources in the following format:

Type

The first term in the above format represents the type of the archive. The term “deb” indicates that it is the repository of binaries, which are pre-compiled files. The term “deb-src” indicates that it is the repository of packages in source file format, which requires compilation in order to use it in the system.

Repository URL

The next term in the above format represents the repository URL (HTTP, HTTPS, or FTP). This term represents the location of the repository from which you want to download the packages.

Distribution

The next term in the above format is either the short codename (i.e., Sid, Buster, Wheezy, Lenny, Jessie, etc.) of the release,  or the development phase of the Debian release (stable, testing, and unstable).

Component

The final term in the above format represents the categories of the Debian package. The available categories of the Debian distribution are main, contrib, and non-free.

Main

This category contains packages that are released under a free license (BSD, GPL, etc.) and that meet the DFSG (Debian Free Software Guidelines). These packages also contain the source code within them, which can be modified and redistributed.

Contrib

This category contains the packages that meet the DFSG (Debian Free Software Guidelines. The packages in the Contrib category are open-source packages, but depend on non-free packages to work.

Non-free

This category contains the packages that do not meet the DFSG (Debian Free Software Guidelines). These packages have some strict license conditions that restrict the usage and redistribution of the software.

Adding a Repository Using the sources.list File

You can add a repository in Debian using the /etc/apt/sources.list file. Here, we will add the VirtualBox repository to the sources.list file.

To add a custom repository to the /etc/apt/sources.list file, follow the steps below:

1. Open the /etc/apt/sources.list file in any editor:

$ sudo nano /etc/apt/sources.list

2. Add the VirtualBox repository in the file:

deb http://download.virtualbox.org/virtualbox/debian stretch contrib

3. Save and close the file.

4. After adding the repository in the /etc/apt/sources.list file, run the “apt update” command to make the system aware of the added repository.

$ sudo apt update

Now that the VirtualBox repository has been added, you can proceed with the installation procedure.

An alternative way to add repository in the Debian sources is by adding the repository in a separate file under the /etc/apt/sources.list.d/ directory. Follow the steps below to do so:

1. Create a file in the /etc/apt/sources/list.d/ directory with the .list suffix.

$ sudo nano /etc/apt/sources.list.d/virtualbox.list

2. Add the VirtualBox repository in the file:

deb http://download.virtualbox.org/virtualbox/debian stretch contrib

3. Save and close the file.

4. After adding the repository in a separate file under the /etc/apt/sources.list.d directory, run the “apt update” command to make the system aware of the added repository.

$ sudo apt update

Now that the VirtualBox repository has been added, you can proceed with the installation procedure.

That is all there is to it! I hope you now have a clear understanding of what the sources.list file is and what each of the terms in the file means.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.