We have local mirrors for Ubuntu (Debian) at http://ubuntu.wikimedia.org/ubuntu/ (https://mirrors.wikimedia.org/debian/). I want to configure clients to prefer downloading/only download packages from these mirrors instead of http://nova.clouds.archive.ubuntu.com/ubuntu/ (http://httpredir.debian.org/debian/). I can do this successfully by replacing the URLs in /etc/apt/sources.list, however I am interested in doing this without changing /etc/apt/sources.list so that the customization is obvious and can easily be reverted.

I have created /etc/apt/sources.list.d/wikimedia-mirror.list with the content:

deb http://ubuntu.wikimedia.org/ubuntu/ trusty main universe
deb-src http://ubuntu.wikimedia.org/ubuntu/ trusty main universe

and /etc/apt/preferences.d/wikimedia-mirror.pref with:

Package: *
Pin: origin "ubuntu.wikimedia.org"
Pin-Priority: 501

After apt-get update, this will cause packages from the mirror to have priority 501, yet apt-get will download those packages from the original sources:

scfc@toolsbeta-t68121-trusty:~$ apt-cache policy zsh-doc
  Installed: (none)
  Candidate: 5.0.2-3ubuntu6
  Version table:
     5.0.5-4ubuntu1~ubuntu14.04.1 0
        100 http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty-backports/main amd64 Packages
     5.0.2-3ubuntu6 0
        500 http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
        501 http://ubuntu.wikimedia.org/ubuntu/ trusty/main amd64 Packages
scfc@toolsbeta-t68121-trusty:~$ sudo apt-get install zsh-doc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 35 not upgraded.
Need to get 2,274 kB of archives.
After this operation, 5,856 kB of additional disk space will be used.
Get:1 http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty/main zsh-doc all 5.0.2-3ubuntu6 [2,274 kB]
Fetched 2,274 kB in 3s (631 kB/s)    
Selecting previously unselected package zsh-doc.
(Reading database ... 38984 files and directories currently installed.)
Preparing to unpack .../zsh-doc_5.0.2-3ubuntu6_all.deb ...
Unpacking zsh-doc (5.0.2-3ubuntu6) ...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...
Setting up zsh-doc (5.0.2-3ubuntu6) ...

This behaviour is consistent with the documentation in apt_preferences(5):

Several instances of the same version of a package may be available when the sources.list(5)` file contains references to more than one source. In this case apt-get downloads the instance listed earliest in the sources.list(5) file. The APT preferences do not affect the choice of instance, only the choice of version.

Is there any way to prefer the mirror over the original sources without changing /etc/apt/sources.list? Can files in /etc/apt/sources.list.d ever be "earlier" than /etc/apt/sources.list? Is there perhaps a configuration option that could be (ab)used for "mapping" the URLs?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.