Debian 12 默认使用 deb.debian.org,在国内访问时常出现下载慢、apt update 卡住或超时的情况。换成国内镜像可以明显改善,下面记录一次换清华源的完整过程。
前置确认
先确认系统版本代号,避免源地址与发行版不匹配:
cat /etc/os-releaseDebian 12 的代号是 bookworm,下面的源地址都按这个代号写。
备份原配置
改之前先留一份原件,出问题可以随时还原:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak编辑源列表
sudo nano /etc/apt/sources.list把内容替换为:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware保存退出:Ctrl + X,再按 Y 并回车。
更新索引并验证
sudo apt update判断是否成功看两点:输出里不应出现 404 Not Found,也不应有 NO_PUBKEY 或签名校验失败的报错。如果只有部分源失败,先检查地址里的代号是否写成了 bookworm。
需要装源码包时,再把对应 deb-src 行的注释去掉,否则保持注释状态可以加快 apt update。
几点说明
bookworm-security这条不要省。安全更新走的是debian-security仓库,和主仓库分开。non-free-firmware是 Debian 12 新增的独立组件,无线网卡、显卡固件都从这里取,删掉可能导致驱动装不上。- 三个仓库(
bookworm、bookworm-updates、bookworm-backports)的代号必须一致,混用不同版本会出现依赖冲突。 - Debian 12 仍以
/etc/apt/sources.list为主;APT 2.6 也支持 deb822 格式的.sources文件,若用那种写法,目录在/etc/apt/sources.list.d/,不要和本文件里的同源条目重复。
评论
发表评论