假设我们使用的是Ubuntu 18.04 LTS(Bionic Beaver)。
我知道切换当前使用的APT镜像的GUI方法。
用户应打开“软件和更新”(software-properties-gtk
或software-properties-kde
),然后导航到Ubuntu软件(Kubuntu Software)选项卡,然后在“从以下位置下载”列表中选择镜像:
但是如何从命令行切换APT镜像?
注释/更新:
/etc/apt/sources.list
以防止输入错误并自动选择正确的镜像。software-properties-gtk
在系统中保存镜像地址的位置也很有趣)。镜像服务器列表由Python库检索(该get_server_list
过程在中定义,/usr/lib/python3/dist-packages/aptsources/distro.py
并从中调用/usr/lib/python3/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.py
)。
解决方案是使用名为的工具apt-mirror-updater
。它可以从pip
/安装pip3
:
sudo pip3 install apt-mirror-updater
功能性:
用法:apt-mirror-updater [选项]
apt-mirror-updater程序通过启用可用镜像的发现,可用镜像的排名,镜像之间的自动切换和健壮的软件包列表更新,自动为Debian和Ubuntu进行健壮的apt-get镜像选择。
支持的选项:
-r,--remote-host = SSH_ALIAS
Operate on a remote system instead of the local system. The SSH_ALIAS argument gives the SSH alias of the remote host. It is assumed that the remote account has root privileges or password-less sudo access.
-f,--find-current-mirror
Determine the main mirror that is currently configured in /etc/apt/sources.list and report its URL on standard output.
-b,-查找最佳镜像
Discover available mirrors, rank them, select the best one and report its URL on standard output.
-l,--list-mirrors
List available (ranked) mirrors on the terminal in a human readable format.
-c,--change-mirror = MIRROR_URL
Update /etc/apt/sources.list to use the given MIRROR_URL.
-a,--auto-change-mirror
Discover available mirrors, rank the mirrors by connection speed and update status and update /etc/apt/sources.list to use the best available mirror.
-u,-update,-update-package-lists
Update the package lists using `apt-get update', retrying on failure and automatically switch to a different mirror when it looks like the current mirror is being updated.
-x,--exclude =模式
Add a pattern to the mirror selection blacklist. PATTERN is expected to be a shell pattern (containing wild cards like `?' and `*') that is matched against the full URL of each mirror.
-m,--max = COUNT
Don't query more than COUNT mirrors for their connection status (defaults to 50). If you give the number 0 no limit will be applied. Because Ubuntu mirror discovery can report more than 300 mirrors it's useful to limit the number of mirrors that are queried, otherwise the ranking of mirrors will take a long time (because over 300 connections need to be established).
-v,--verbose
Increase logging verbosity (can be repeated).
-q,-安静
Decrease logging verbosity (can be repeated).
-h,--help
Show this message and exit.
因此,它可以找到最佳的镜像并将其应用于/etc/apt/sources.list
:
sudo apt-mirror-updater --auto-change-mirror
它还允许通过URL选择镜像并将其应用于/etc/apt/sources.list
:
$ apt-mirror-updater --list-mirrors
-----------------------------------------------------------------------------------------------------------------------
| Rank | Mirror URL | Available? | Updating? | Last updated | Bandwidth |
-----------------------------------------------------------------------------------------------------------------------
| 1 | http://mirror.timeweb.ru/ubuntu | Yes | No | Up to date | 6.49 KB/s |
| 2 | http://no.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 6.38 KB/s |
| 3 | http://ftp.aso.ee/ubuntu | Yes | No | Up to date | 5.62 KB/s |
| 4 | http://mirror.plusserver.com/ubuntu/ubuntu | Yes | No | Up to date | 4.77 KB/s |
| 5 | http://nl.archive.ubuntu.com/ubuntu | Yes | No | Up to date | 4.68 KB/s |
...
然后手动选择镜像:
sudo apt-mirror-updater -c "http://mirror.timeweb.ru/ubuntu"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句