一、源文件位置
Ubuntu24.04的源地址配置文件发生改变,不再使用以前的sources.list文件,升级24.04之后,文件格式变为DEB822格式,文件位置如下
/etc/apt/sources.list.d/ubuntu.sources
新旧格式与位置对比
| 项目 | 旧版(传统) | 新版(DEB822) |
|---|---|---|
| 文件位置 | /etc/apt/sources.list | /etc/apt/sources.list.d/ubuntu.sources |
| 配置风格 | 单行 deb/deb-src 语法 | 分段键值(Types, URIs, Suites, Components, Signed-By) |
| 管理方式 | 一个文件全塞 | 模块化、可扩展,便于拆分不同源 |
| 默认使用 | 22.04/23.10 仍常见 | 24.04(Noble)默认采用 |
Sources:
为什么改为 DEB822
DEB822 格式是 APT 的结构化配置,使用键值对提高可读性与可扩展性(如多 URI、签名、组件分段更清晰),并通过 ubuntu.sources 作为主配置入口,便于分模块管理不同源。
操作步骤:在 24.04 中更换镜像源
1. 备份主源文件
bash
sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak
这一步是通用安全操作,防止误改后无法恢复。
2. 编辑 ubuntu.sources(DEB822)
bash
sudo nano /etc/apt/sources.list.d/ubuntu.sources
你将看到以键值对为主的段落结构(Types/URIs/Suites/Components/Signed-By),直接修改 URIs 为国内镜像即可。
3. 更新索引与系统
bash
sudo apt update
sudo apt upgrade
改源后刷新索引以生效。
示例:将 URIs 改为国内镜像
以下示例为 Ubuntu 24.04(代号 noble),将 ubuntu.sources 中的 URIs 替换为国内镜像。注意保持 Suites 与 Components 项一致。
清华大学镜像(TUNA)
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
Suites: noble noble-updates noble-security noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
清华镜像对 DEB822 的支持文档完善,可直接使用上述结构。
阿里云镜像
Types: deb
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-security noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
阿里云明确指出 24.04 起主源位置变更至 ubuntu.sources,并给出 DEB822 示例。
中科大镜像(USTC)
Types: deb
URIs: https://mirrors.ustc.edu.cn/ubuntu/
Suites: noble noble-updates noble-security noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
USTC 与其他国内镜像的 DEB822 用法一致,关键在于替换 URIs 并保持 Suites/Components 组合不变.
多架构或端口镜像的注意事项
- ARM/Ports 架构请使用 ubuntu-ports 的镜像地址,例如阿里云的 https://mirrors.aliyun.com/ubuntu-ports/,其 DEB822 段落需与架构对应。
- 如果你仍保留 /etc/apt/sources.list 的传统条目,APT 仍会读取,但 24.04 的默认主入口是 ubuntu.sources,建议统一改为 DEB822 以减少混乱。
小贴士与常见坑
- 使用 HTTPS 镜像时,确保系统中存在 Ubuntu 的 archive keyring,Signed-By 指向 /usr/share/keyrings/ubuntu-archive-keyring.gpg 是官方推荐路径。
- Suites 请包含 noble、noble-updates、noble-security,是否添加 noble-backports 根据需求选择;漏写会造成部分组件无法获取更新。
- 如果编辑后 apt update 报签名或 404 错误,优先检查 URIs 是否正确、网络连通与 DNS、以及是否误删了关键段落的键名。
快速回退
若有问题,直接回退备份:
bash
sudo mv /etc/apt/sources.list.d/ubuntu.sources.bak /etc/apt/sources.list.d/ubuntu.sources
sudo apt update
评论(没有评论)