Understanding sources.list in Ubuntu and Debian

Understanding the concept of sources.list in Ubuntu will help you understand and fix common update errors in Ubuntu.

I hope you are familiar with the concept of package managers and repositories.

A repository is basically a web server that has packages (software). The package manager gets these packages from the repositories.

How does the apt package manager know the address of the repositories? The answer is sources.list file.

What does sources.list do?

It’s basically a text file that contains the repository details. Each uncommented line represents a separate repository.

Default sources list file in Ubuntu
Sources list files in Ubuntu

The lines follow a specific format, though. It’s usually composed of this:

archive-type repository-url distribution component

I know that’s not easy to understand. Let’s take a look at one of the actual lines:

deb http://archive.ubuntu.com/ubuntu impish main restricted

Archive type is deb here, meaning you’ll get precompiled .deb packages. Another archive type is deb-src which provides the actual source code but usually it is commented out (not used by the system) because a regular user doesn’t need the source code of an application. The deb file lets you install the package.

Repository URL is http://archive.ubuntu.com/ubuntu. In fact, you can visit this URL and see various available folders (that contain the package details).

Index of Ubuntu repository

Next, the distribution is impish. On the actual repository, it is represented as dists. It’s because there are several categories of repositories like impish-security (for security packages), impish-backports (for backported packages) etc. This is why it’s not just the distribution name.

So, you can go to this URL http://archive.ubuntu.com/ubuntu/dists/ and see that impish (codename for Ubuntu 21.10) is one of the available folders among many other choices here.

Sources.list explanation

The component is one of the five types of default Ubuntu repositories.

Understanding Ubuntu's repository structure from sources.list

You can combine more than one (if available) in the same line, actually. Instead of writing two lines like this:

deb http://archive.ubuntu.com/ubuntu impish main
deb http://archive.ubuntu.com/ubuntu impish restricted

You write two of them together like this:

deb http://archive.ubuntu.com/ubuntu impish main restricted

This means when you have a repository detail like “deb http://archive.ubuntu.com/ubuntu impish main” in the sources.list, it gets software packages details stored at http://archive.ubuntu.com/ubuntu/dists/impish/main/

The distribution code name is important

Does this sound interesting? I bet it is.

Now imagine if someone is using an old, unsupported version of Ubuntu like Ubuntu 20.10 codenamed Groovy Gorilla.

The sources.list file will contain repository URL like deb http://archive.ubuntu.com/ubuntu groovy main. And then it becomes problematic because if you visit http://archive.ubuntu.com/ubuntu/dists URL, you won’t find groovy folder here. Since Ubuntu 20.10 is no longer maintained, its folder has been removed.

As a result, Ubuntu will show an error like ‘release file not found’ or ‘error 404 repository not found’.

Did you notice that my sources.list file had some entries with focal (Ubuntu 20.04)? It’s because I had upgraded my Ubuntu 20.04 system to 20.10 to 21.04 and now to 21.10.

sources.list file and sources.list.d directory

If you look at the /etc/apt directory, you’ll notice a directory called sources.list.d.

Sources List directory in Ubuntu

The idea is that the primary sources.list file is for the official Ubuntu repositories and for any external repositories and PPA, you add a .list file (with the repository details) in this sources.list.d directory.

External repository information are added in sources.list.d directory

This makes managing the repositories easier as you don’t mess up with the default repositories. The external repositories can be easily disabled (by adding # in front of the repository details) or removed (by removing its corresponding .list file).

You can use the graphical Software & Updates tool for the same purpose if you use Ubuntu desktop. The entries in ‘Ubuntu Software’ tab come from the sources.list file and the entries in the ‘Other Software’ tab come from the files in sources.list.d directory.

Software & Updates tool in Ubuntu

The next step

Is that clear so far? You have learned plenty of ‘behind the curtains’ things.

If the entries in sources.list are incorrect or duplicated, your system will throw errors when you try to update your Ubuntu system.

As you are familiar with the concept of package management, repository and sources.list, understanding the root cause and fixing the common update errors in Ubuntu becomes an easier task.

Don't just take my word for that. Put your newly learned knowledge to some good use by understanding the root cause of this error 👇

Fixing “Target Packages is configured multiple times” Error in Ubuntu & Debian Based Linux Distributions
Recently, when I was updating Ubuntu via command line, I encountered a warning that complained about target package being configured multiple times. The exact message after running sudo apt update command looked like this: Fetched 324 kB in 6s (50.6 kB/s)Reading package lists… DoneBuildi…

You'll also have a better understanding of how external repositories work.

Installing Packages From External Repositories in Ubuntu [Explained]
You have some ideas about installing packages in Ubuntu with apt command. Those packages come from Ubuntu’s repositories. How about third-party or external repository? No, I am not talking about PPA here. Sooner or later, you’ll come across installation instructions that goes in at least f…

Still have doubts or questions? Please leave a comment below and I'll answer them.

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.