N0r*_*ert 6 updates update-manager package-management command-line apt
假设我们使用的是 Ubuntu 18.04 LTS (Bionic Beaver)。
我知道切换当前使用的 APT 镜像的 GUI 方法。
用户应该打开软件和更新(software-properties-gtk
或software-properties-kde
)并导航到Ubuntu 软件(Kubuntu 软件)选项卡,然后在从列表下载中选择镜像:
但是如何从命令行切换 APT 镜像呢?
注释/更新:
/etc/apt/sources.list
以防止拼写错误并自动正确选择镜像。software-properties-gtk
(镜像地址保存在系统中的位置也很有趣)。一些解决方案(在我的 Ubuntu 18.04.1 LTS 上测试):https : //github.com/jblakeman/apt-select.git
pip install apt-select
Run Code Online (Sandbox Code Playgroud)
或者:
pip3 install apt-select
Run Code Online (Sandbox Code Playgroud)
将脚本添加到 PATH 以从任何地方运行它(使其永久化):
export PATH=$PATH:~/.local/bin/apt-select
Run Code Online (Sandbox Code Playgroud)
从美国获取顶级镜像生成新的sources.list::
apt-select --country US
Run Code Online (Sandbox Code Playgroud)
从前 3 个镜像中选择,包括一周前最后更新的镜像:
apt-select -c -t 3 -m one-week-behind
Run Code Online (Sandbox Code Playgroud)
从 5 个对您的机器具有最低延迟的美国镜像中进行选择:
$ apt-select --country US -t 5 --choose
Run Code Online (Sandbox Code Playgroud)
镜像服务器列表由 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
Run Code Online (Sandbox Code Playgroud)
功能:
用法:apt-mirror-updater [选项]
apt-mirror-updater 程序通过启用可用镜像的发现、可用镜像的排名、镜像之间的自动切换和强大的软件包列表更新,为 Debian 和 Ubuntu 自动执行强大的 apt-get 镜像选择。
支持的选项:
-r, --remote-host=SSH_ALIAS
Run Code Online (Sandbox Code Playgroud)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
Run Code Online (Sandbox Code Playgroud)Determine the main mirror that is currently configured in /etc/apt/sources.list and report its URL on standard output.
-b, --find-best-mirror
Run Code Online (Sandbox Code Playgroud)Discover available mirrors, rank them, select the best one and report its URL on standard output.
-l, --list-mirrors
Run Code Online (Sandbox Code Playgroud)List available (ranked) mirrors on the terminal in a human readable format.
-c, --change-mirror=MIRROR_URL
Run Code Online (Sandbox Code Playgroud)Update /etc/apt/sources.list to use the given MIRROR_URL.
-a, --auto-change-mirror
Run Code Online (Sandbox Code Playgroud)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
Run Code Online (Sandbox Code Playgroud)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=模式
Run Code Online (Sandbox Code Playgroud)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
Run Code Online (Sandbox Code Playgroud)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
Run Code Online (Sandbox Code Playgroud)Increase logging verbosity (can be repeated).
-q, --安静
Run Code Online (Sandbox Code Playgroud)Decrease logging verbosity (can be repeated).
-h, --help
Run Code Online (Sandbox Code Playgroud)Show this message and exit.
因此,它允许找到最佳镜像并将其应用于/etc/apt/sources.list
:
sudo apt-mirror-updater --auto-change-mirror
Run Code Online (Sandbox Code Playgroud)
它还允许通过 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 |
...
Run Code Online (Sandbox Code Playgroud)
然后手动选择镜像:
sudo apt-mirror-updater -c "http://mirror.timeweb.ru/ubuntu"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14389 次 |
最近记录: |