Restore default apt repositories in sources.list from command line

I'm not sure what you want, but:

  • The parent repository is always http://archive.ubuntu.com/ubuntu - everything else is a mirror of this. The other primary mirrors all have a domain of the form <cctld>.archive.ubuntu.com, where the two character short code is the Country Code Top Level Domain. You can find additional mirrors with their status at Launchpad.
  • The distribution codename is part of the channel (the third term). You can use lsb_release -sc to find that out, and it's the first word of the release pretty name in lowercase (trusty for Trusty Tahr, for example).
  • There are five channels: <codename>, <codename>-security, <codename>-updates, <codename>-backports and <codename>-proposed. The first is necessary as it is the base, the second is highly recommended as it contains security fixes, the fourth only if you need some package backported from a newer release and the fifth only if a developer asks you to enable it for testing a possible fix.
  • There are four repository sections: main, multiverse, universe and restricted (What's the difference between multiverse, universe, restricted and main?)

So you can always create a safe sources.list which contains just:

deb http://archive.ubuntu.com/ubuntu <codename> main multiverse universe restricted
deb http://archive.ubuntu.com/ubuntu <codename>-security main multiverse universe restricted

If you want a command to do this:

printf 'deb http://archive.ubuntu.com/ubuntu %s main multiverse universe restricted\n' "$(lsb_release -sc)"{,-security} > /etc/apt/sources.list

Or, lsb_release isn't available, use /etc/os-release from the base-files package:

printf 'deb http://archive.ubuntu.com/ubuntu %s main multiverse universe restricted\n' "$(. /etc/os-release; printf "%s" "$UBUNTU_CODENAME")"{,-security} > /etc/apt/sources.list

In addition to the Launchpad list, the list provided by the Software Sources program is from /usr/share/python-apt/templates/Ubuntu.mirrors, which is from the python-apt-common package. This package is only an indirect Suggests dependency of apt, so it may not be installed by default on a server.


If you understand what each line stands for in /etc/apt/sources.list, you can generate your own list. For example a line in my sources.list is,

deb http://archive.ubuntu.com/ubuntu/ trusty main

It has 4 sections:

  • Section 1: The first section is deb here which means it is a repository of all the binary packages. only other possible value is deb-src which means its a repository of source codes.
  • Section 2: This section contains the URI of the repository (http://us.archive.ubuntu.com/ubuntu/ in this case). The URI can vary for mirrors e.g. if you want to use the official US mirror then the URI will be http://us.archive.ubuntu.com/ubuntu/.
  • Section 3: It contains the codename (and channel name) of the release you are using, in this case trusty which is the codename of my Ubuntu release (14.04 LTS). you can find yours by lsb_release -sc. For example, If you are using 12.04 the codename will be "precise". Now to declare other channels e.g. to declare security channel you need to use trusty-security.

  • Section 4: This section contains "section names" of the repository. There are usually 4 section names used: main, restricted, universe, multiverse. You can put all the section names in the same line of declaring a repository or you can use different lines for each of the sections but there must not be any duplicate entry. If you read the /etc/apt/sources.list, then you will see the description of packages each of these sections contains.