HowTo: Make and simplify sources.list files
With Penguin-fans everywhere madly hitting Ubuntu mirrors worldwide today grabbing the Final Release of Ubuntu 8.10 Intrepid Ibex (including myself), people are discovering that using the official major country mirrors can be a bit slow. In the case of Australia, the official mirror is au.archive.ubuntu.com but it’s much slower than many of the other official and unofficial Australian mirrors, especially if your local ISP keeps their own mirror.
It makes sense then, to change your setup to point to a faster mirror rather than rely on the primary.
There are a couple of ways to change your sources, including simply going to System->Administraion->Software Sources and changing the “Download from:” dropbox to another official mirror closer to you. One of my favourite speedy Australian mirrors is Internode. They are registered as an official Australian mirror and automatically appear in this drop-down list, but if your local ISP has their own unofficial mirror, or you have your own mirror at home, then you won’t be able to select it from this list, so you need to do some manual work instead.
Jump into a terminal and type in the following:
$ sudo gedit /etc/apt/sources.list
This will bring up the current sources.list into your text editor. Go through every line that doesn’t have a leading hash and add one, so that every single line is commented out, eg:
This line is not commented
#This line IS commented out because of the leading hash
Do that for all un-commented lines. This will totally disable your sources.list file. “Woah”, you say “Don’t I need that to update my system?” Yes you do, however there is method to my madness.
Save and exit your sources.list file and then type in the following:
$ sudo gedit /etc/apt/sources.list.d/mynewsources.list
This will create a new empty file in your text editor. Now type in the following:
# Ubuntu Intrepid Binaries source.list deb http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid main restricted universe multiverse deb http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-updates main restricted universe multiverse deb http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-security main restricted universe multiverse #deb http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-backports main restricted universe multiverse #deb http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-proposed main restricted universe multiverse # Ubuntu Intrepid Source source.list deb-src http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid main restricted universe multiverse deb-src http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-updates main restricted universe multiverse deb-src http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-security main restricted universe multiverse #deb-src http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-backports main restricted universe multiverse #deb-src http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid-proposed main restricted universe multiverse
(The Intrepid-Backports and Intrepid-Proposed lines should remain commented out with the leading hash unless you really, really need them)
Save and exit.
Now type in:
$ sudo apt-get update
All of a sudden you see that your machine is pulling all its package lists from Internode’s mirror instead of your old repository! How does this work? And why is this source list so much shorter than the one that Ubuntu already provides?
Apt-get can handle multiple source.list files
By default Apt reads the /etc/apt/sources.list file and normally you would have this setup just for Ubuntu only.
The /etc/apt/sources.list.d/ directory (note the .d on the end of the directory name) can contain any number of other source list files. They can be named anything you like as long as they end in “.list”, so “foobar.list” and “banana.list” are perfectly valid names – Apt will look at all of them. The idea behind being able to make multiple sources lists is that you can setup multiple sources for various software packages, eg; you might have a separate source list to get Virtualbox from Sun’s website, Wine from the WineHQ website, Medibuntu from the Medibuntu website, etc.
Do you have to have separate source lists? Not at all – you can have multiple deb and deb-src lines going to different sites in the one sources.list file if you like. Having multiple separate lists just allows you to keep things clean and tidy and easily allows you to setup other workstations with various repository sources by simply copying a file over instead of editing the sources.list file everytime.
Shortening your sources.list
Now in the above example, all we ultimately did was setup Internode’s Ubuntu repository in a separate source list file but we could have just as easily modified the /etc/apt/sources.list file and replaced all occurences of the official AU mirror’s address with Internode’s address instead, but by showing you how to create your own source list, I’ve also shown you how to simplify the content of the Ubuntu source list too, so you can compare them side by side.
As you know, the deb line tells Apt which address to go to followed by the variant of Ubuntu you are using (in this case “Intrepid”) and then you specify the repository section you are interested in. in the case of Ubuntu, there are four sections in each repository group called “Main”, “Restricted”, “Universe” and “Multiverse”. This could be expressed in your source list like:
deb http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid main
deb http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid restricted
deb http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid universe
deb http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid multiverse
But this is a lot of unnecessary text. You can cover the lot with one line by specifying the sections together on one line:
deb http://mirror.internode.on.net/pub/ubuntu/ubuntu intrepid main restricted universe multiverse
Repeat this for each repository, eg: intrepid-updates, intrepid-security etc and you end up with something much shorter and easier to read than the default sources.list file.
The main reason the default Ubuntu etc/apt/sources.list file is so big is to explain to the new user what the file is about and how to configure it. A lot of it is just comment lines.
So, now you can apply this to setting up your favourite Ubuntu mirror yourself be it your local ISP’s mirror or even your own mirror at home. Just replace the URL in the source list with the new one.
Like
first.
Yes, you are the first comment on this post. Congratulations!
Cheers! that was a good refresher.
Oh and I found your site via a googling on apt-mirror, good article loads of examples.
Thanks
Thanks very much for this. I started the updating my Ubuntu server to 9.04 via the GUI update manager, and noticed that the 3rd step (Getting New Packages) was chugging along at 40-60kB/s.
Being an Internode customer, I cancelled it, updated my sources.list as per your advice, and recommenced the Distro Upgrade. It’s flying along at my ADSL2+ speed now – cheers.
You’re welcome! Improved download speed is always bliss.
Thank you so much, after searching various sites this was the only method that got my problem solved.