跳到主要内容

Ubuntu APT 安装源的配置

Ubuntu 在不同硬件架构下使用的软件源不同:

  • 主流源 (archive.ubuntu.com) → 面向 x86/x86_64 架构
  • 非主流源 (ports.ubuntu.com) → 面向 ARM (arm64/armhf)、PowerPC、RISC-V 等架构

由于 RockChip 系列开发板 基于 ARM64 架构,因此在其 Ubuntu 系统中需要使用 非主流 ports.ubuntu.com 安装源 或其镜像。

操作环境

  • LKD3588 / LPA3588 / LPB3588 等RK全系开发板、主机
  • Ubuntu 20.04 / 22.04 / 24.04 ARM64 版本

一、主流源与非主流源区别

对比项主流源 archive.ubuntu.com非主流源 ports.ubuntu.com
适用架构x86 (i386), x86_64 (amd64)ARM (arm64, armhf), PowerPC, RISC-V, s390x 等
使用场景桌面 PC、服务器开发板、嵌入式系统、树莓派、RockChip 等 SoC 平台
软件包分类main / restricted / universe / multiverse与主流源一致
是否可互换不能跨架构使用(不同架构的软件包不兼容)必须与��系统架构一致

二、中国大陆可用镜像源列表

为提升速度,推荐使用以下镜像站替换 ports.ubuntu.com

优先级镜像站地址
1阿里云https://mirrors.aliyun.com/ubuntu-ports/
2南方科技大学https://mirrors.sustech.edu.cn/ubuntu-ports/
3上海交大https://mirror.sjtu.edu.cn/ubuntu-ports/
4中国科技大学https://mirrors.ustc.edu.cn/ubuntu-ports/
5华为云https://www.huaweicloud.com/special/ubuntuports-jingxiang.html 部分节点提供 ubuntu-ports 镜像,需根据华为云官方文档配置。

三、配置方法一:编辑 /etc/apt/sources.list

Ubuntu 22.04 (Jammy) + 阿里云 Ubuntu-Ports 镜像为例:

# 备份原配置
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 编辑文件
sudo vim /etc/apt/sources.list

内容示例:

# 阿里云 Ubuntu-Ports 非主流架构镜像(deb二进制包仓库)
deb [arch=arm64,armhf] https://mirrors.aliyun.com/ubuntu-ports jammy main restricted universe multiverse
deb [arch=arm64,armhf] https://mirrors.aliyun.com/ubuntu-ports jammy-updates main restricted universe multiverse
deb [arch=arm64,armhf] https://mirrors.aliyun.com/ubuntu-ports jammy-backports main restricted universe multiverse
deb [arch=arm64,armhf] https://mirrors.aliyun.com/ubuntu-ports jammy-security main restricted universe multiverse

# 源码仓(deb-src)为选配:修改 Ubuntu-Ports 系统包源码时需要
# deb-src https://mirrors.aliyun.com/ubuntu-ports jammy main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports jammy-updates main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports jammy-backports main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports jammy-security main restricted universe multiverse

更新源:

# 清理 apt 缓存,避免索引文件使用旧缓存
sudo apt clean

# 更新软件源索引
sudo apt update

sudo apt clean 可选,用于清理缓存,避免索引使用旧文件;多数情况下只需 sudo apt update

四、配置方法二:Deb822 .sources 文件(推荐)

保存为 /etc/apt/sources.list.d/aliyun-ubuntu-ports.sources

方案 A:只配二进制仓(deb)的直接链接")

Types: deb
URIs: https://mirrors.aliyun.com/ubuntu-ports/
Suites: jammy jammy-updates jammy-backports jammy-security
Components: main restricted universe multiverse
Architectures: arm64

方案 B:二进制仓(deb) + 源码仓(deb-src) + 源码仓(deb-src)的直接链接")

Types: deb deb-src
URIs: https://mirrors.aliyun.com/ubuntu-ports/
Suites: jammy jammy-updates jammy-backports jammy-security
Components: main restricted universe multiverse
Architectures: arm64

刷新索引:

# 清理 apt 缓存,避免索引文件使用旧缓存
sudo apt clean

# 更新软件源索引
sudo apt update

sudo apt clean 可选,用于清理缓存,避免索引使用旧文件;多数情况下只需 sudo apt update

五、主流源的配置示例(对比)

在 x86_64 PC 上运行 Ubuntu 22.04 (Jammy) 时,常见配置为:

# Ubuntu 官方主流源
deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-security main restricted universe multiverse

# 源码仓
# deb-src http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu jammy-security main restricted universe multiverse

若在中国大陆,可使用清华大学的主流源镜像:

# 清华大学主流源(x86_64)
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-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security main restricted universe multiverse

# 源码仓
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security main restricted universe multiverse

六、总结

  1. RockChip ARM64 开发板 → 必须使用非主流源(ports.ubuntu.com 或其镜像)

  2. 提供了两种配置方式:

    • 编辑 /etc/apt/sources.list(传统方式)。
    • 使用 Deb822 .sources 文件(推荐方式)。
  3. 同时展��示了 常见中国大陆镜像源,并对比了 主流源与非主流源 的差异,避免混淆。


附录:源码仓 (deb-src) 使用说明 使用说明的直接链接")

在 Ubuntu 的 APT 源配置中:

  • deb → 提供预编译好的二进制包(直接安装即可使用)。
  • deb-src → 提供源码包(用于下载、修改和重新编译)。

是否需要开启源码仓,取决于实际使用需求:

一、需要配置源码仓的场景

  1. 需要编译或修改官方软件包
    • 使用 apt source <package> 下载源码,修改后重新打包。
    • 典型场景:修改内核、驱动或库的编译选项,修补 bug,适配 Rockchip 平台。
  2. 需要学习或调试源码
    • 下载源码以研究官方打包方式、补丁内容。
    • 常见于 systemd、glibc、apt 等系统核心软件。
  3. 需要构建依赖
    • 使用 apt-get build-dep <package> 安装编译依赖时,需要源码仓提供元数据。
    • 比如:编译 ffmpeg、gstreamer 等大型软件时,常常需要 apt-get build-dep
  4. 参与 Ubuntu/Debian 开发或二次打包
    • 需要源码仓来获取标��准的打包文件和规则。

二、不需要配置源码仓的场景

  1. 只安装和使用二进制软件
    • 普通软件安装:apt install vim gcc ffmpeg
  2. 嵌入式系统存储空间有限
    • 源码仓索引文件较大,占用额外磁盘和带宽。
    • Rockchip 开发板一般无需长期启用源码仓。
  3. 系统更新/安全补丁升级
    • apt update && apt upgrade 只依赖二进制包,不需要源码仓。

三、使用建议

  • 开发/调试阶段:启用源码仓。
  • 普通使用阶段:禁用源码仓以节省空间和流量。
  • 临时需求:需要时再注释/取消注释 deb-src 行。
  • 在开发板上:推荐默认关闭 deb-src,仅在开发/调试时临时启用。