Adding a repository in Debian is a process to specify the path in the sources.list file to download the software packages. The path refers to the online location where the software packages are located and this online location is known as the repository.
Many packages come in the default repository of Debian. Moreover, some third-party software packages can be installed on Debian by adding their repositories. In this tutorial, we will walk through the methods of adding a repository in Debian.
What are the Reasons for Adding a Repository in Debian?
The reasons for adding a repository in Debian are:
- The updated versions of the software packages can be installed
- Can install the software packages that are not included in the default repository of Debian
- Easily manage the packages of the repository using the package manager
What are the Methods of Adding a Repository in Debian?
The addition of the repository in Debian can be done by the below-mentioned methods:
All the above-mentioned methods for adding a repository in Debian are explained in the next section.
Method 1: Add a Debian Repository by Editing sources.list File
The first method of adding a repository in Debian is by editing the configuration file, named as sources.list and located at /etc/apt/ directory. Follow the steps to add the repository in Debian by editing a configuration file of Debian.
Step 1: Open the Terminal
The first step is to open the terminal of the Debian to run commands:
Step 2: Open the Configuration File
Now open the configuration file of the Debian with the help of the nano text editor:
$ sudo nano /etc/apt/sources.list
Step 3: Add a Debian Repository
Next, in the file, add the repository with the addition of the line as shown:
deb [repository_url] [distribution] [component]
The explanation of the above line is:
- Use the “deb” keyword
- Add the URL of the repository
- Specified the distribution name of the Debian
- Define the component which can be main, contrib, and non-free
For example, the repository of the Debian is added by following the above line:
deb http://ftp.debian.org/debian stable main contrib non-free
After inserting the line, save the file with the shortcut key CTRL+S and exit the nano text editor.
Step 4: Update the Packages
After adding the repository, update the packages of Debian:
$ sudo apt update
Step 5: Install the Package
Finally, install the package with the apt package manager whose repository is added in the configuration file of Debian.
Method 2: Add a Debian Repository by Using an add-apt-repository Command
Another method of adding the repositories in Debian is by using the add-apt-command. To use the add-apt-repository command, first, install it:
$ sudo apt install software-properties-common
After installing it, add the Debian repository by running the command:
$ sudo add-apt-repository deb http://ftp.debian.org/debian stable main contrib non-free
Update the packages of the Debian:
$ sudo apt update
The final step is to install the package whose repository is added. To remove the PPA repository, use the “r” option of the add-apt-repository:
$ sudo add-apt-repository -r deb http://ftp.debian.org/debian stable main contrib non-free
Method 3: Add a Debian Repository by Using a GUI Method
The last and more convenient method of adding the repository in Debian is by using the GUI approach. For this, open the “Software and Updates” and then click on it:
Click on the “Other Software” option and then click on the “Add” button:
Add the path of the repository and then click on the “Add Source” button:
These are the three different methods of adding the repositories on Debian.
Conclusion
To add a Debian repository, either edit the sources.list file or use the GUI method by accessing the “Software & Updates”. Another method of adding the Debian repository is by using the add-apt-command utility. All these methods are explained in this tutorial with the help of the examples.