Wednesday, March 2, 2016

Restore default apt repositories in sources.list from command line


I am looking for the best method to restore /etc/apt/sources.list to default from the command line.


Is there no way to reference the source code of the package which generates this file or something like that? I want a trusted and version-independent way of restoring this file.


Solutions Ruled Out


Before you mark this as a duplicate, note that I have reviewed this question already. It is only applicable if you have the Ubuntu GUI available. This question is specific to the command line.


I have also reviewed this question where the accepted solution is someone pasted the contents of their sources.list file. This is not an appropriate way to restore the file as the intentions of the person providing the file contents cannot be verified and the file is subject to change with new releases.


I checked out the generator at simplelinux.ch, but this is also not from Ubuntu so I do not plan to use it.



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 .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: , -security, -updates, -backports and -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  main multiverse universe restricted
deb http://archive.ubuntu.com/ubuntu -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



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.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...