APT checks the health of all the packages, and dependencies of the package before installing it. APT fetches packages from one or more repositories. A repository (package source) is basically a network server. The term "package" refers to an individual file with a .deb extension that contains either all or part of an application. The normal installation comes with default repositories configured, but these contain only a few packages out of an ocean of free software available.
In this tutorial, we learn how to add the package repository to Debian.
1. Adding repository from terminal
You can add a package repository to Debian 2 ways from the shell: manually or using apt. The package repository information is stored in the file named
/etc/apt/sources.list. And also can be stored in any file inside the directory
Add repository manually
To add a repository manually you have to edit the /etc/apt/sources.list file. The entries in this file have a syntax as:
Archive-Type Repository-URL Distribution Component1 Component2 Component3
Archive Type - The first word of the line can be
deb-src. Deb indicates the archive holds the .deb packages and deb-src indicates the archive has the source packages.
Repository URL - This entry is the URL of the repository from where the package is to download.
Distribution - This can be either the release code name, alias (such as bullseye) or the release class (oldstable, stable, testing, unstable) respectively.
Component - This can be main, contrib, or non-free. The
main contains DFSG compliant package part of Debian distribution. The
contrib contains the DFSG compliant package which has dependencies not in the
non-free contains packages that don't comply with DFSG.
For example, let's add the VirtualBox repository to Debian Bullseye. First open /etc/apt/sources.list file to edit.
sudo nano /etc/apt/sources.list
Now you can add the package repository line to the file.
deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian bullseye contrib
Below is the /etc/apt/sources.list file from my Debian 11 system, it contains some of the official Debian repository which was added during the Debian installation and you can also see the newly added repository.
Instead of adding to /etc/apt/sources.list file, you can also create custom source file with .list extension inside /etc/apt/sources.list.d/ directory and add the repository in that file. This also works.
Once the apt repository is added, make sure to update the package index:
sudo apt update
Add repository using add-apt-repository
The add-apt-repository is a Python script used to add a regular APT repository or PPA. This utility is included in the
The basic syntax of the
add-apt-repository command is as follows:
add-apt-repository [options] repository
For example, you need to install Docker from the official repository. First, update the package index and install all the dependencies.
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Import the repository GPG key:
sudo curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
Now add the Docker repository using add-apt-repository:
sudo add-apt-repository 'deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable'
This will add the repository information to the etc/apt/sources.list file.
Next, update the package index and then install the docker package.
sudo apt update apt-cache policy docker-ce
To remove the enabled repository, type:
sudo add-apt-repository --remove 'deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable'
The add-apt-repository also allows adding PPA Repository. PPA stands for Personal Package Archive, which allows developers to create their own repositories.
For example to add the PPA repository for libreoffice, type:
sudo add-apt-repository ppa:libreoffice/libreoffice-7-0
Once PPA is added, you can install the respective package using apt.
2. Adding repository from GUI
Alternatively, you can add the package repository from Debian Gui. I am using Debian 11 with the Gnome Desktop environment.
From the Desktop search for 'Software & Updates'
In 'Software & Updates', choose the second tab 'Other Software'
Click 'Add' button, then add the APT line and click the 'Add Source' button to update the
In this tutorial, we learned how to add package repository to Debian. thanks for reading, please let us know your feedback in the comment section.