适用对象:ARM64 设备(如 R2S / 树莓派等)上运行 Ubuntu 24.04(noble),APT 默认指向
ports.ubuntu.com,更新速度慢或链路不稳定。
目标:保持“官方仓库内容等价”的前提下,切换到国内镜像加速,并移除不适合生产环境的-proposed测试仓库。
1. 背景现象:APT 命中 ports.ubuntu.com
在 ARM64 Ubuntu 上执行 apt update,常见输出类似:
http://ports.ubuntu.com noble InReleasenoble-updates / noble-security / noble-backports- 甚至出现
noble-proposed
其中 ports.ubuntu.com 是 Ubuntu 官方用于 非 x86 架构(ARM 等) 的主仓库入口。它是“源站”,内容权威,但在亚洲链路上经常出现吞吐偏低的问题。
2. 关键点:ARM 的“国内镜像”必须是 ubuntu-ports 镜像
很多人换源失败,是因为误用只同步 x86 的镜像路径(如普通 ubuntu/),而 ARM 设备应使用 ubuntu-ports。
镜像等价关系如下:
- 源站:
ports.ubuntu.com - 镜像:各高校/云厂商对
ubuntu-ports仓库的同步副本(rsync 同步) - 软件真实性:仍由 Ubuntu 官方签名校验(GPG),镜像只提供“更近的下载点”
3. 配置现状确认:使用传统 sources.list(而非 ubuntu.sources)
Ubuntu 24.04 有两类常见 APT 配置方式:
- 官方安装介质:常见
.sources(debian822 格式) - SBC/厂商/社区镜像:仍使用传统
/etc/apt/sources.list
当系统存在以下特征时,基本可判断为“传统 sources.list”模式:
ls /etc/apt
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d
若看到:
/etc/apt/sources.list有多行deb .../etc/apt/sources.list.d/为空/etc/apt/sources.list.d/ubuntu.sources不存在
则直接修改 sources.list 即可。
4. 换源原则:保持仓库等价,只替换镜像地址
4.1 先备份
cp /etc/apt/sources.list /etc/apt/sources.list.bak
4.2 将 ports.ubuntu.com 替换为清华 ubuntu-ports
将 /etc/apt/sources.list 内容替换为:
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-security main restricted universe multiverse# deb-src 可选:不需要源码时建议不启用
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble main restricted universe multiverse
5. 重要建议:关闭 noble-proposed(测试仓库)
如果原配置包含:
noble-proposed
建议移除。原因很简单:
-proposed是候选/测试更新仓库- 依赖关系更容易波动
- 对长期运行的节点/网关/基础设施并不友好
- 生产环境通常不启用
换句话说:换源不是风险点,proposed 才是风险点。
6. 验证换源是否生效
建议执行一次“清缓存 + 更新索引”:
apt clean
apt update
成功的标志是输出中出现:
https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports ...
并且索引下载速度显著提升。
7. 执行升级:apt upgrade
在索引刷新后,常见会提示有大量可升级包:
apt list --upgradable
apt upgrade
典型升级内容包括:
noble-updates、noble-security的正式补丁- glibc、openssl、systemd、python 等基础组件更新
- 可能出现
t64命名(24.04 的 time_t 过渡相关包名),属于正常现象
7.1 关于 linux-libc-dev 的误解澄清
升级列表中出现 linux-libc-dev 并不等价于“要升级内核”。
linux-libc-dev是用户态编译/接口头文件- 是否升级内核以
uname -r是否变化为准 - SBC 场景常用“厂商/社区内核 + Ubuntu 用户态”,这类升级通常不影响当前运行内核
8. 升级后的稳妥收尾
升级完成回到 shell 后,建议做一次“健康检查式收尾”:
8.1 修复依赖与清理
apt -f install
apt autoremove --purge
apt clean
8.2 确认 proposed 没有被重新启用
grep -R "proposed" /etc/apt/sources.list /etc/apt/sources.list.d || echo "no proposed"
8.3 检查是否需要重启服务/系统(可选但推荐)
如系统安装了 needrestart:
needrestart
未安装则:
apt install needrestart
needrestart
该工具会列出哪些服务/进程仍在使用旧库,需要重启服务来完成更新“落地”。
9. 效果总结:官方等价 + 国内加速 + 稳定配置
完成以上步骤后,状态通常变为:
- 软件仓库:仍是 Ubuntu 官方签名体系(等价内容)
- 下载节点:从源站切换为国内镜像(显著加速)
- 稳定性:移除
-proposed后更符合长期运行节点的生产实践 - 后续维护:继续
apt update && apt upgrade即可