APT包管理器支持两种源配置格式。除了sources.list的传统格式,还有一种是DEB822格式。
如果不知道怎么配置,参考以下内容。

DEB822格式:
/etc/apt/sources.list.d/debian.sources(容器镜像默认使用)。

本文将替换掉原本的debian.sources,换成清华源(tsinghua.sources)以提高使用apt的国内下载速度。

注:先确保支持DEB822格式且使用!
只需要两个命令即可完成,下面直接上命令!

命令1:取消使用原本的配置

通过以下命令,重命名原本的debian.sources debian.sources.bak,这样子该文件就不会生效了,同时留个备份方便之后恢复。

mv /etc/apt/sources.list.d/debian.sources /etc/apt/sources.list.d/debian.sources.bak

命令2:添加清华源配置

新的配置将会放到/etc/apt/sources.list.d/tsinghua.sources

tee /etc/apt/sources.list.d/tsinghua.sources << 'EOF'
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian/
Suites: trixie trixie-updates trixie-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# Types: deb-src
# URIs: https://mirrors.tuna.tsinghua.edu.cn/debian/
# Suites: trixie trixie-updates trixie-backports
# Components: main contrib non-free non-free-firmware
# Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

# 安全更新源(推荐使用官方源以获得及时更新)
Types: deb
URIs: https://security.debian.org/debian-security
Suites: trixie-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

# 如果希望使用镜像站的安全更新源,可以取消注释以下配置并注释上面的官方源
# Types: deb
# URIs: https://mirrors.tuna.tsinghua.edu.cn/debian-security
# Suites: trixie-security
# Components: main contrib non-free non-free-firmware
# Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF

大功告成!
如果不是debian 13,参考这个配置文件:

tee /etc/apt/sources.list.d/tsinghua.sources << 'EOF'
Types: deb
URIs: http://mirrors.tuna.tsinghua.edu.cn/debian
Suites: bookworm bookworm-updates bookworm-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
Types: deb-src
URIs: http://mirrors.tuna.tsinghua.edu.cn/debian
Suites: bookworm bookworm-updates bookworm-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: http://mirrors.tuna.tsinghua.edu.cn/debian-security
Suites: bookworm-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb-src
URIs: http://mirrors.tuna.tsinghua.edu.cn/debian-security
Suites: bookworm-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF

验证

可以手动查看一下配置是否正确

cat /etc/apt/sources.list.d/tsinghua.sources

查看当前配置的源

apt policy

若显示的都是清华源,说明成功配置。
然后验证一下是否成功(update或其他操作均可)

# 清理缓存
apt clean
# 更新软件包索引
apt update

若从清华源正常拉取资源,说明一切正常

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐