apt 执行速度慢,apt源加速镜像(树莓派 Debian Ubuntu )

apt 执行速度慢,apt源加速镜像(树莓派 Debian Ubuntu )

在使用 Linux 安装软件包的过程中,经常用到的命令是 apt

但是一般 ubuntu 或者树莓派、又或者 Debian 默认的仓库源位于国外,速度可能比较慢

下面通过本站的加速服务,可以加快 apt 仓库源的下载速度

cd /etc/apt
vim sources.list

sources.list 文件中,在所有的 http 或者 https 链接前新增加速前缀。

加速前缀链接是: https://pd.zwc365.com/seturl/

也就是原来的链接是 https://www.baidu.com 则直接在原来的链接前加上我的链接就行了:

https://pd.zwc365.com/seturl/https://www.baidu.com

下面以树莓派的 apt 仓库源为例:

原来的仓库源地址(文件路径: /etc/apt/sources.list):

deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# deb http://ftp.de.debian.org/debian sid main
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi

当使用加速后的仓库源地址:

deb https://pd.zwc365.com/seturl/http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# deb http://ftp.de.debian.org/debian sid main
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
deb-src https://pd.zwc365.com/seturl/http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi

然后再执行 apt-get update 。此时的速度便会快很多了。

上面是用树莓派举例,Ubuntu、Debian 等使用 apt 进行软件包管理的系统都可以用同样的方式加快速度

对于任意系统版本都可以用同样的方式进行加速,例如:Ubuntu 20、18、16、14 等版本。所以,即便是以后推出的新系统,只要一个加速链接即可,不需要专门去找对应的镜像了。

加速项目主页

Ubuntu 20 版本 apt 镜像加速

下面是原有的 Ubuntu apt 源地址文件内容(文件路径: /etc/apt/sources.list):

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ focal main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ focal universe
# deb-src http://archive.ubuntu.com/ubuntu/ focal universe
deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner

deb http://security.ubuntu.com/ubuntu/ focal-security main restricted
# deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted
deb http://security.ubuntu.com/ubuntu/ focal-security universe
# deb-src http://security.ubuntu.com/ubuntu/ focal-security universe
deb http://security.ubuntu.com/ubuntu/ focal-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ focal-security multiverse
deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable
# deb-src [arch=amd64] https://download.docker.com/linux/ubuntu focal stable

使用加速源后的文件内容(文件路径: /etc/apt/sources.list):

你只需要分别在每行 http 链接前,添加加速链接前缀即可。这份文件是以 Ubuntu 20 为例,如果你的系统是其它的 Linux。操作步骤相同,在链接前使用加速前缀即可

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb https://pd.zwc365.com/seturl/http://archive.ubuntu.com/ubuntu/ focal main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb https://pd.zwc365.com/seturl/http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb https://pd.zwc365.com/seturl/http://archive.ubuntu.com/ubuntu/ focal universe
# deb-src http://archive.ubuntu.com/ubuntu/ focal universe
deb https://pd.zwc365.com/seturl/http://archive.ubuntu.com/ubuntu/ focal-updates universe
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb https://pd.zwc365.com/seturl/http://archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal multiverse
deb https://pd.zwc365.com/seturl/http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb https://pd.zwc365.com/seturl/http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner

deb https://pd.zwc365.com/seturl/http://security.ubuntu.com/ubuntu/ focal-security main restricted
# deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted
deb https://pd.zwc365.com/seturl/http://security.ubuntu.com/ubuntu/ focal-security universe
# deb-src http://security.ubuntu.com/ubuntu/ focal-security universe
deb https://pd.zwc365.com/seturl/http://security.ubuntu.com/ubuntu/ focal-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ focal-security multiverse
deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable
# deb-src [arch=amd64] https://download.docker.com/linux/ubuntu focal stable

此加速源的优点在于:没有缓存,非镜像(仅仅是转发流量,类似代理功能),任意源均可用

Copyright: 采用 知识共享署名4.0 国际许可协议进行许可

Links: https://zwc365.com/2021/01/04/apt-origin-update

Buy me a cup of coffee ☕.