✅How to add repositories in Debian — step by step

Work with repositories in debian it’s very simple once you know how to add them and update the system. This opens up the possibility of having more options when installing new programs or updating those we have to more modern versions.

How to add repositories in Debian — step by step

Where is the list of repositories

The list with all repositories in Debian it is in a file called sources.list. To open this file and work with it, we must have “root” permissions. Open a terminal and type this command:

sudo gedit /etc/apt/sources.list

How to add a repository in Debian

We can use the “gedit” editor or another of our choice, such as “vim”, “nano”, or the one we are used to using.

It is in this file that we will make the changes we need when adding repositories – also modifying them, disabling them and even deleting them – in the system.

How to add a repository in Debian

Let’s take as an example that we want to add the Docker repository to our Debian. A simple way – and one that can be used for other programs and services – is to use the Debian Source List Generator (abbreviated as DSLG) page. If you didn’t know it, you should have it among your bookmarks or favorites. This website generates the links that we need to put in the sources.list to add repositories in Debian.

Debian source list generator

When we enter the DSLG page, we find a series of repository sources already enabled, as shown in the previous image. What we need to do is select – in the form dropdown as highlighted in the image – the “Stable Buster” option.

The previous step requires DSLG to show us the list with all the links to the most important repositories in Debian. We can scroll the page until we find what we are interested in, in our case “Docker CE”, or search using [ctrl]+[F].

Once we find “Docker CE”, we mark it, then go to the bottom of the page to click on the “Build” button. DSLG will show us the generated sources.list below. We should only be interested in copying what corresponds to Docker, as you can see in the following image:

docker repository on debian

First we’ll paste the repository line at the end of our sources.list file (the same one we opened from the terminal before). We save the change. And we leave the editor.

We will now copy the GPG key that the DSLG website gave us – as it appears in the image – and paste it into the terminal. We press “Enter” to accept the command.

Then we will update the list of repositories in Debian from the terminal by typing:

sudo apt update

and after…

sudo apt upgrade

With this, we already have the new Docker repository added to our system. Remember that this is just an example, you can add any repository you want by following the steps above.

Do you have any questions related to this tutorial that you would like to ask us? Remember that in the comments section you can write to us so that together we can give you an answer.