How to manage sources.list on Debian 11 "Bullseye"

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to make changes to sources.list file on Debian 11.

sources.list file contains the sources from where packages are going to be downloaded on your system. Adding or removing sources from the sources.list is easy, and it can be done easily by following steps below.

Backup sources.list

Sources.list file is a very important file for your system, because all the repositories from where your system gets packages are defined into this file. So if this file gets misconfigured, then you won't be able to use any of the repositories, which means you won't be able to update or download packages on your system. To prevent this from happening, you can save a copy of the working sources.list just in case.

We are going to copy /etc/apt/sources.list to /home/owlhowto

sudo cp /etc/apt/sources.list /home/owlhowto

Replace /home/owlhowto with the path where you want to save the copy of sources.list

You can copy this file to any path you want.

Edit sources.list

sources.list is located at /etc/sources.list. To edit this file, you can use any text editor

For example, if you want to edit sources.list by using the nano text editor, then run the command below. You can also use any other text editor.

sudo nano /etc/sources.list

Add sources

To add a source address on sources.list, is easy. Copy the source address that you want to add, and simply paste it to sources.list.

💡
Note: There are multiple ways to paste something on Linux. You can paste by clicking the wheel button on your mouse, you can paste by right clicking and then choosing "Paste", finally you can paste by using the shortcut - CTRL + SHIFT + V

Next, save changes by pressing CTRL + X and confirm with Y. Now, you need to update your system to make sure the added source is added correctly

sudo apt update

You should see the new source that you added on the output of the update command as shown below. This means the source is working and added correctly.

Remove Sources

Removing sources can be done the same way as adding sources. Open sources.list with a text editor, and then simply remove the source address that you don't want to use.

💡
Note: If you don't want to delete a source, you can deactivate it by commenting it out. Simply add # in the beginning of the source line that you want to disable, and the source becomes inactive. 

Then make sure to save changes, by pressing CTRL + X. To confirm that the source that you removed is removed correctly and not active in the system, you need to update your system

sudo apt update

If the source that you removed was removed successfully, then this source shouldn't be showing on the update list on the terminal

Conclusion

In this tutorial, you learned how to add and remove sources from the sources.list file on Debian 11. We also explained how to verify when adding or removing sources is done correctly.