HowTo - edit your sources.list

Share your wisdom. Not for support questions!

Moderator: How-to Curator

HowTo - edit your sources.list

Postby cynwulf » March 3rd, 2011, 3:39 pm

HowTo - edit your sources.list

Which editor?

Methods of editing vary, there are gui tools that can edit this, personally I don't trust them and I've seen the results of some files which have been improperly edited as a result of said tools, posted up on various messageboards - I will cover this in the last section of this guide. To cut a long story short: a horrible mess. Don't do it, the terminal and terminal based text editors are not as frightening as you might think.

The only reliable way to edit a sources.list file is using an old fashioned terminal based text editor such as vim or nano. You may still want to use a gui text editor such as gedit, mousepad, leafpad or whatever. That's fine - do it if you feel the need, but you will need to run it as root from the terminal as follows:

Code: Select all
$ gksu gedit /etc/apt/sources.list

Code: Select all
$ kdesu kate /etc/apt/sources.list


If you went clicking through with a file manager, you won't be able to edit it, as you would need to authenticate as root. You could launch a file manager as root, but I'm not going to cover that here.

To avoid all that unnecessary hassle, the better method (In my opinion) is this:

Code: Select all
$ su
# nano /etc/apt/sources.list


Or

Code: Select all
$ su
# vim /etc/apt/sources.list



On to sources.list

Getting started, running the command/clicking or a combination of both you should be presented with the contents of a file something like this:

Code: Select all
#This is a comment
deb http://ftp.us.debian.org/debian/ wheezy main
deb-src http://ftp.us.debian.org/debian/ wheezy main

deb http://security.debian.org/ wheezy/updates main
deb-src http://security.debian.org/ wheezy/updates main

deb http://ftp.us.debian.org/debian wheezy-updates main
deb-src http://ftp.us.debian.org/debian wheezy-updates main


We will approach this in a piecemeal fashion.

#
The first line is a comment. Any line beginning with a # (hash) symbol is ignored by apt when it reads the list of repositories. # is also used to disable an entire line (more later).

deb
The second line begins with "deb ", all you need to know about this for now is that this signifies a binary repository (repo for short). This is where actual compiled (ready to run) programs are pulled from. So if you were to install, e.g. pidgin instant messenger it would most likely be pulled from a "deb" repo.


http://ftp.us.debian.org/debian/
The next part of the same line is the repo's mirror url (the webserver where packages are stored). In this case we can clearly see that it's the US mirror that is listed. You would have set this up during install, but it can be changed at any time to a mirror nearer to your geographical location. Debian worldwide mirror sites

wheezy
Next up is the actual distribution branch/codename. This can be somewhat confusing for new users because of the often interchangeable use of release code names and the branch name. As you can see we're using wheezy, which is the stable branch. We could be clever and change all incidences of "wheezy" to "stable" and it would still work. In fact there would be no difference because it's exactly the same thing... at the moment. Read more below or skip.
More: show
As of writing these are the codenames in use:

squeeze : oldstable
wheezy : stable
jessie : testing
sid : unstable

In X months/years from now when the current testing release "jessie" goes stable this list will look very different:

wheezy : oldstable
jessie : stable
? : testing
sid : unstable

This in effect means that anyone with "stable" in their sources list will start pulling the new stable distribution as soon as it is released... this can be potentially disastrous. A planned upgrade is always better than an unplanned one.

So why on earth would anyone use "stable" in their sources.list instead of the actual release code name "wheezy" you may ask? The simple answer is: they shouldn't. The only people that really need to use the branch names are those that want to stay with the testing distribution. For the sid/unstable release it doesn't matter much, as sid is always unstable.


main
Finally we have the repository name. This tells us that this is main debian official repo for this release. It contains only free software.

deb-src
The third line begins with "deb-src ", this signifies a package source code repository. Apart from the "deb-src" part, this line is exactly the same as the previous one. If you are not going to build from source then chances are you may not need this repo, so you can simply disable it as follows:

Code: Select all
#This is a comment
deb http://ftp.us.debian.org/debian/ wheezy main
#deb-src http://ftp.us.debian.org/debian/ wheezy main

deb http://security.debian.org/ wheezy/updates main
#deb-src http://security.debian.org/ wheezy/updates main

deb http://ftp.us.debian.org/debian wheezy-updates main
#deb-src http://ftp.us.debian.org/debian wheezy-updates main


Note that I have also disabled some other deb-src lines. If you need to re-enable it you can remove the comment. Now onto the sections:

The first pair of lines are our main debian repos. This is where the vast bulk of the software you will install comes from.

The second set of repositories are the security repos. These are where you will get your security patches.

Finally "wheezy-updates" is what used to be called the "volatile" repo. You can read more about this here: http://www.debian.org/volatile/ and here https://wiki.debian.org/StableUpdates

There are various other repos you can add, I won't cover those here, but all repos use the same syntax, it's just a case of adding them to the bottom of the list. For example if you wanted to add the backports repo, you edit your sources file as follows:

Code: Select all
#This is a comment
deb http://ftp.us.debian.org/debian/ wheezy main
#deb-src http://ftp.us.debian.org/debian/ wheezy main

deb http://security.debian.org/ wheezy/updates main
#deb-src http://security.debian.org/ wheezy/updates main

deb http://ftp.us.debian.org/debian wheezy-updates main
#deb-src http://ftp.us.debian.org/debian wheezy-updates main

#wheezy Backports
deb http://ftp.us.debian.org/debian wheezy-backports main


Note the optional descriptive comment.

contrib non-free

If you must enable these - read below.
More: show
In additional to the "main" repo, almost all repos have "non-free" and "contrib" portions containing non dfsg or only partially compliant packages. To enable these you add them to the end of the relevant deb/deb-src line(s) as follows:

Code: Select all
deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free




Using the edited sources.list

When you are done editing, it's just a case of saving and exiting. For the contents of the repo to actually be of any use however it is necessary to do the following:

Code: Select all
apt-get update


Or

Code: Select all
aptitude update


This reads the contents of the file and refreshes the package list. If you did not do this you would be still working to the previous list. At this point note any errors which could mean you made a mistake in your sources file.

Troubleshooting

Offline installs

If you installed without an active network connection, you may end up with a mess something like this example below:
Code: Select all
#

deb cdrom:[Debian GNU/Linux 7.2.0 _Wheezy_ - Official amd64 DVD Binary-1 20131012-14:05]/ wheezy contrib main

# Line commented out by installer because it failed to verify:
#deb http://ftp.us.debian.org/debian/ wheezy main
# Line commented out by installer because it failed to verify:
#deb-src http://ftp.us.debian.org/debian/ wheezy main
# Line commented out by installer because it failed to verify:
#deb http://security.debian.org/ wheezy/updates main
# Line commented out by installer because it failed to verify:
#deb-src http://security.debian.org/ wheezy/updates main


Doing..
Code: Select all
# apt-get update
# apt-get upgrade

... with a sources file like this will only retrieve package information and install packages from the listed cdrom. That's not much use. But don't panic!

To fix this is simple - the tutorial above explains it all clearly. Obviously the "deb cdrom" line will need commenting out and the other disabled repos enabled. When you're done, it's a case of updating the package listing and you're ready to go. If you get lots of connection errors it's likely your network is not set up correctly, so test and troubleshoot that and ensure it's working first.

Copying someone else's sources.list from the web

Don't do it! You may think "this looks like a clued up guy, I will use his sources.list". But are you running the same release, branch, or even the same distro as this person? Do you have the same apt.conf and preferences files as them? Is it out of date/obsolete? Do you know what all those extra repos you've never heard of are for? If you can't answer these questions, then you probably shouldn't be copying and pasting someone else's sources file. Regardless: you certainly should not be copying and pasting someone else's sources.list if you don't understand how sources.list works.

Finally the really stupid stuff

Never, ever, ever use repositories or especially PPAs from another distribution*, i.e. a Debian derivative such as Linux Mint or Ubuntu. "but Mint/Ubuntu is based on Debian, surely it's the same thing in a different box and besides I've seen the 'pros" doing it" I hear you say.

The answer is yes and no. While Ubuntu is based on Debian, it is not binary compatible with Debian. So installing something from an Ubuntu repo, could overwrite parts of and break Debian packages. Remember, a package is unpacked and the bits (files) are distributed all over your system to their correct places. Apt's system of dependencies prevents two packages from installing the same files, overwriting each other, causing version conflicts and generally breaking stuff, etc, etc, etc. Apt cannot do this properly if you introduce repos from another incompatible distribution. The 'pros' may install certain packages or they may have unpacked and repackaged them first? The 'pros' may also have a broken dependency tree... Again if you're not sure you shouldn't be even considering it. In short: don't do it unless you really know what you're doing.

*Unless you are a pro that knows what to install, how to install it and how to fix it if it all breaks - if so then you shouldn't need to read this howto anyway. Go ahead - and remember if it breaks you get to keep both pieces.


Discussion thread

***Updated 17/01/14***
* Updated for wheezy
* Added mention of PPAs in the FTRSS section (should have been included from day one)
* Tidied up some of the code blocks
* Changed to new style backports syntax
* Corrected "squeeze/updates" to "wheezy-updates" (should have been a hyphen) and added link to Debian wiki StableUpdates page.
* Added link to backports instructions
* Prioritised apt usage over aptitude
cynwulf
 
Posts: 1997
Joined: April 26th, 2011, 2:46 pm

Return to HowTo

Who is online

Users browsing this forum: Yandex [Bot] and 3 guests

x