Ubuntu 26.04 必须使用 deb822 格式的 /etc/apt/sources.list.d/ubuntu.sources 文件换源,硬套旧版 sources.list 会导致 Invalid record format 错误;需备份后清空重写清华或阿里等镜像源配置,并确保 Suites 为 resolute 及 Signed-By 路径正确。

Ubuntu换源不是“改一行就能用”,关键看系统版本——ubuntu.sources(deb822格式)在26.04及之后是默认且强制的,硬套老教程里的sources.list会直接报Invalid record format错误。
怎么判断该用哪种源文件格式
先确认你的Ubuntu版本和对应源格式:
- 运行
cat /etc/os-release | grep VERSION_CODENAME,如果输出是VERSION_CODENAME=resolute(即26.04 LTS),必须用/etc/apt/sources.list.d/ubuntu.sources - 如果是
focal(20.04)、jammy(22.04)或noble(24.04),仍可沿用传统/etc/apt/sources.list,但新版apt也支持deb822,推荐统一迁移到ubuntu.sources -
ls -l /etc/apt/sources.list.d/如果看到ubuntu.sources且非空,说明系统已启用deb822;若只有sources.list,则走旧路径
修改 ubuntu.sources(26.04+ 必须这么做)
直接覆盖写入,别拼接、别追加,否则格式错乱:
Ubuntu 26.04 LTS(代号“Resolute Raccoon”)是Canonical于2026年4月23日发布的下一代长期支持版操作系统,提供长达10年的技术支持。它搭载Linux 7.0内核与GNOME 50桌面环境,全面转向Wayland协议,并引入Rust重写的核心工具以增强安全性。官方提供适用于AMD64和ARM64架构的桌面及服务器ISO镜像,是追求前沿技术与极致稳定的开发者
- 备份:
sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak - 编辑:
sudo nano /etc/apt/sources.list.d/ubuntu.sources - 清空原内容,粘贴清华源(HTTPS、
Signed-By路径必须准确):
Types: deb URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ Suites: resolute resolute-updates resolute-backports resolute-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
- 阿里源只需改
URIs行:https://mirrors.aliyun.com/ubuntu/,其余不变 - 保存后不用重启,但
sudo apt clean再sudo apt update才生效
改 sources.list(仅限旧版或降级兼容场景)
适用于22.04/24.04等仍默认用该文件的系统,注意三点:
- 别漏掉
-security和-updates行,否则apt update会报404 - 所有URL必须用
https(清华/中科大/阿里均已强制HTTPS,http会拒绝连接) - 版本代号必须匹配,比如
jammy不能写成bionic,否则apt找不到仓库索引 - 示例(22.04 jammy):
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
换源后常见失败点
很多问题不是源本身不对,而是环境没清理干净:
-
sudo apt clean必做——旧缓存可能残留错误签名或过期元数据 - 遇到
GPG error或NO_PUBKEY,不是密钥没装,而是Signed-By路径写错或keyring文件不存在,检查/usr/share/keyrings/ubuntu-archive-keyring.gpg是否存在 -
apt update卡在某个repo不动?大概率是DNS污染或镜像站临时不可用,换一个源(比如从清华切到阿里)立即验证 - 图形界面里“软件和更新”设置里改源,本质还是改
ubuntu.sources,但GUI可能不刷新deb822字段,建议优先命令行操作
最易被忽略的是:26.04起sources.list文件即使存在也不被读取,只认ubuntu.sources——删了它也没用,改错了照样失败。

















