Key Takeaways
The "Software & Updates" GNOME tool allows you to add repositories by typing the APT line and pressing the "Add Source" button.
You can add a repository to Debian by adding it to the sources.list file.
Another way to add a repository is to use the add-apt-repository command-line utility.
Debian Linux utilizes the APT package manager, which relies on a predefined set of repositories for package installation. However, if you wish to access software packages that are not included in the official Debian repositories, you will need to add them yourself. This tutorial will guide you through the process of adding third-party repositories to your Debian system.
We will be explaining several methods for achieving this, allowing you to select the one that suits your needs the best. If you are uncertain about which method to choose but are using the GNOME desktop environment, we recommend following the Software & Updates method outlined below.
Add a Repository to Debian Using the "Software & Updates" Tool
For the purpose of this demonstration, we will be showcasing the steps on the Debian 12 version, accompanied by the GNOME Desktop Environment. It is important to note that these techniques are also applicable to previous versions including Debian 10 and 11.
If you are using the GNOME Desktop Environment, you should have a tool called "Software & Updates" that allows you to easily add repositories. To access it, click on "Activities" in the top left corner of your screen.
In the search bar, start typing "Software & Updates". You should see the tool appear. The icon has a globe on it. Click on that icon to open it.
When the tool launches, you will notice four tabs. Click on the "Other Software" tab.
You will see a list in that tab. At the bottom, press the "Add" button.
Now you need to input the third-party repository URL in the below format:
deb [repository URL] [distribution] [component(s)]
The "deb" keyword represents the repository type. In succession, include the URL or link to the repository. Append the distribution name (bullseye, bookworm) or class (stable, testing) after the URL. Finally, specify the component type (main, contrib, non-free). This string is known as an APT line in Debian.
In our example, we'll add the repository of Wine. Following the above format, it will look like this:
deb https://dl.winehq.org/wine-builds/debian bookworm main
Enter your APT line in the text box. Then press "Add Source."
You'll be asked to enter your password. Enter it and press "Authenticate."
And that should add the repository to your list.
Add a Repository to Debian by Editing the sources.list File
To add new package repositories to Debian Linux in a more conventional manner, refer to the following instructions. Debian Linux provides a comprehensive list of available repositories in the "sources.list" file, which can be found in the "/etc/apt" directory. To understand the functioning of these repositories, we will begin by accessing and examining this file. Feel free to use your preferred text editor for this tutorial. However, we will be using the Nano text editor.
To open the file in Nano, run the below command:
sudo nano /etc/apt/sources.list
You can see all available repositories from the screenshot. You must add your repository in the below format:
deb [repository URL] [distribution] [component(s)]
If we want to add the repository of Wine in the file, for example, this is the line we need to add:
deb https://dl.winehq.org/wine-builds/debian bookworm main
Enter your repository with the proper format into the file.
Once done, save the file with the Ctrl+O keyboard combination. Then exit from the editor with Ctrl+X.
To make the changes take effect, update the repository cache with this command:
sudo apt update
And the new repository should work now.
Add a Repository to Debian Using the add-apt-repository Command
The following method demonstrates a straightforward command for adding repositories to Debian. This command is capable of adding both third-party repositories and Personal Package Archive (PPA) to the sources.list file. The syntax of this command is as follows:
add-apt-repository [OPTIONS] [Repository URL]
So now let's use this command to add our sample repository.
sudo add-apt-repository 'deb https://dl.winehq.org/wine-builds/debian bookworm main'
Press the Enter button to confirm when prompted.
For certain repositories, you might have to sign them with a GPG key to ensure their verification. Otherwise, the command to add the repository will not be successful.
If you try to add a repository that already exists, then you'll get a message saying that. See the below example:
After adding the repository, you need to update the repository list for the changes to take effect. Update your system with this command:
sudo apt update
And that should add your target repository.
If you want to remove a repository, you can add the --remove flag for that in the command. Let's remove our added repository. See the below command:
sudo add-apt-repository --remove 'deb https://dl.winehq.org/wine-builds/debian bookworm main'
That successfully removed the repository.
Debian Repositories Unlocked
With this newfound understanding of adding third-party repositories on Debian Linux systems, you can now overcome any software limitations you may have encountered before. This will enable you to effortlessly install your preferred applications, be it Steam for gaming or Docker for development purposes.