Debian 12(bookworm)及之后默认使用DEB822格式,配置文件为/etc/apt/sources.list.d/debian.sources;Debian 11(bullseye)及更早用传统格式,走/etc/apt/sources.list。

直接改 /etc/apt/sources.list 或 /etc/apt/sources.list.d/debian.sources 就行,但必须先确认 Debian 版本和配置格式,否则 apt update 会报错或部分源失效。
怎么判断该用 sources.list 还是 debian.sources?
Debian 12(bookworm)及之后默认用 DEB822 格式,配置文件是 /etc/apt/sources.list.d/debian.sources;Debian 11(bullseye)及更早用传统 One-Line-Style,走 /etc/apt/sources.list。运行下面命令可快速确认:
ls -l /etc/apt/sources.list.d/debian.sources 2>/dev/null || echo "不存在,大概率是旧格式"
如果输出 “No such file”,说明系统还在用 /etc/apt/sources.list;如果存在且非空,优先编辑它,/etc/apt/sources.list 会被忽略。
- DEB822 格式不支持注释行(# 开头的行会被跳过),也不支持混合 deb/deb-src 写在同一块里
- 传统格式里
deb-src行默认被注释,如需源码得手动取消注释 - Debian 13(trixie)已移除 non-free 组件,只保留
non-free-firmware,写错会导致apt update报 404
网易源怎么配才不报 404?
网易镜像站不支持 HTTPS(截至 2026 年 9 月),必须用 http:// 协议,且路径末尾不能带斜杠。常见错误是把 https://mirrors.163.com/debian/ 当成通用前缀直接套用——它只适用于旧版(buster/bullseye),新版要按 suite 名拼全路径。
- Debian 11(bullseye):
deb http://mirrors.163.com/debian/ bullseye main non-free contrib - Debian 12(bookworm):
deb http://mirrors.163.com/debian/ bookworm main non-free non-free-firmware contrib - Debian 13(trixie):
deb http://mirrors.163.com/debian/ trixie main contrib non-free-firmware(注意没有non-free) - 安全更新源必须单独写:
deb http://mirrors.163.com/debian-security/ bullseye-security main,路径里不能漏掉-security
清华源为什么有时 apt update 慢或失败?
清华源本身稳定,但失败多因本地环境没配好。最常踩的坑是:没装 apt-transport-https 就直接写 https:// 地址,或 keyring 缺失导致签名验证失败。
- 先执行:
sudo apt install apt-transport-https ca-certificates(Debian 11+ 默认已装,但容器或最小化安装可能没) - DEB822 格式下,必须显式指定
Signed-By字段,例如:Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg - 清华源的安全更新地址是
https://mirrors.tuna.tsinghua.edu.cn/debian-security(无/bookworm-security后缀),写成.../bookworm-security会 404 - 如果用脚本批量替换,注意别把原有
deb-src行里的deb-src错替成deb,否则源码下载失效
换源后 apt update 还报错怎么办?
核心检查点就三个:版本名是否匹配当前系统、协议是否可用、路径是否拼错。不要依赖网上搜到的“万能配置”。
- 查当前版本:
lsb_release -sc(输出如bookworm) - 临时切 HTTP 测试:
sudo sed -i 's/https:/http:/g' /etc/apt/sources.list*,成功再换回 HTTPS - 删掉所有
cdrom:行——新装系统常残留这一行,apt会优先尝试挂载光盘,超时后才 fallback 到网络源 -
apt update报 “The repository does not have a Release file” 通常是因为 suite 名(如trixie)写成了testing或拼错,必须严格对应lsb_release -sc输出
真正麻烦的是混用两种格式:比如在 debian.sources 存在时还往 sources.list 里写内容,apt 会静默忽略后者,排查时容易误判。

















