在不改变/etc/apt/sources.list的情况下select本地镜像?

我们在http://ubuntu.wikimedia.org/ubuntu/(https://mirrors.wikimedia.org/debian/ )为Ubuntu(Debian)提供本地镜像。 我想configuration客户端更喜欢下载/只从这些镜像,而不是http://nova.clouds.archive.ubuntu.com/ubuntu/(http://httpredir.debian.org/debian/ )下载软件包。 我可以通过replace/etc/apt/sources.list的URL来成功地完成此操作,但是我希望在更改/etc/apt/sources.list 情况下执行此操作以便自定义操作很明显,并且可以轻松地还原。

我已经创build了/etc/apt/sources.list.d/wikimedia-mirror.list内容:

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

/etc/apt/preferences.d/wikimedia-mirror.pref与:

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

apt-get update ,这将导致镜像包具有优先级501,但apt-get将从原始源下载这些包:

 scfc@toolsbeta-t68121-trusty:~$ apt-cache policy zsh-doc 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: zsh-doc 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) ... scfc@toolsbeta-t68121-trusty:~$ 

此行为与apt_preferences(5)的文档一致:

sources.list (5)`文件包含对多个源的引用时,几个相同版本的包的实例可能是可用的。 在这种情况下, apt-get会sources.list (5)文件中最早下载列出的实例。 APT偏好不影响实例的select,只影响版本的select。

有没有什么办法可以在不改变/etc/apt/sources.list情况下使镜像优先于原始数据源? /etc/apt/sources.list.d中的/etc/apt/sources.list.d是否可以比/etc/apt/sources.list更早? 有没有可能是一个configuration选项,可以(ab)用于“映射”的url?