Ubuntu 24.04 Noble 配置国内源:DEB822 新格式与 3 大主流镜像源配置详解 Ubuntu 24.04 Noble 配置国内源DEB822 新格式与 3 大主流镜像源配置详解最近升级到 Ubuntu 24.04 Noble Numbat 的用户可能会发现传统的/etc/apt/sources.list文件不见了取而代之的是/etc/apt/sources.list.d/ubuntu.sources文件。这其实是 Ubuntu 24.04 引入的 DEB822 格式源配置文件相比旧格式更加清晰易读。1. DEB822 格式简介与优势DEB822 格式是 Debian 项目提出的一种新的软件源配置格式相比传统的单行格式它具有以下优势结构化更清晰每个字段单独一行便于阅读和维护支持多行描述可以添加注释说明不会影响解析更安全支持签名验证减少中间人攻击风险更灵活可以轻松添加或删除特定组件典型的 DEB822 格式配置文件如下Types: deb URIs: http://mirrors.ustc.edu.cn/ubuntu/ Suites: noble noble-updates noble-backports noble-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg2. 配置前的准备工作在开始配置前我们需要做一些准备工作备份原有配置sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak检查当前 Ubuntu 版本lsb_release -a确保输出中包含Codename: noble安装必要的工具如果尚未安装sudo apt install nano vim -y3. 三大主流镜像源 DEB822 配置3.1 清华大学镜像源配置清华大学 TUNA 镜像源是国内最受欢迎的 Ubuntu 镜像源之一速度稳定且更新及时。sudo nano /etc/apt/sources.list.d/ubuntu.sources将以下内容写入文件Types: deb deb-src URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ Suites: noble noble-updates noble-backports noble-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg提示如果不需要源码包可以删除deb-src类型以加快更新速度。3.2 阿里云镜像源配置阿里云镜像源适合阿里云 ECS 用户使用内网速度极快。sudo nano /etc/apt/sources.list.d/ubuntu.sources内容如下Types: deb URIs: http://mirrors.aliyun.com/ubuntu/ Suites: noble noble-updates noble-backports noble-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg3.3 中科大镜像源配置中国科学技术大学镜像源在教育网内速度优势明显。sudo nano /etc/apt/sources.list.d/ubuntu.sources内容如下Types: deb URIs: https://mirrors.ustc.edu.cn/ubuntu/ Suites: noble noble-updates noble-backports noble-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg4. 验证配置并更新软件包配置完成后需要更新软件包列表sudo apt update如果一切正常你应该能看到类似以下输出命中:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu noble InRelease 命中:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-updates InRelease 命中:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-backports InRelease 命中:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-security InRelease 正在读取软件包列表... 完成为了验证新源确实生效可以尝试安装一个小软件sudo apt install neofetch -y5. 常见问题与解决方案5.1 更新时出现 GPG 错误如果遇到类似以下的错误W: GPG 错误https://mirrors.tuna.tsinghua.edu.cn/ubuntu noble InRelease: 由于没有公钥无法验证下列签名 NO_PUBKEY 3B4FE6ACC0B21F32可以通过以下命令解决sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F325.2 源速度测试与选择可以使用netselect-apt工具测试哪个镜像源速度最快sudo apt install netselect-apt netselect-apt noble5.3 恢复默认配置如果需要恢复默认配置sudo rm /etc/apt/sources.list.d/ubuntu.sources sudo cp /etc/apt/sources.list.d/ubuntu.sources.bak /etc/apt/sources.list.d/ubuntu.sources sudo apt update6. 高级配置技巧6.1 混合使用多个镜像源DEB822 格式支持在一个文件中配置多个镜像源系统会自动选择最快的源Types: deb URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ http://mirrors.aliyun.com/ubuntu/ Suites: noble noble-updates noble-backports noble-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg6.2 为特定组件使用不同源可以为不同的组件指定不同的镜像源Types: deb URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ Suites: noble Components: main restricted Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg Types: deb URIs: http://mirrors.aliyun.com/ubuntu/ Suites: noble Components: universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg6.3 添加第三方 PPA 源对于第三方 PPA 源仍然可以使用传统的add-apt-repository命令sudo add-apt-repository ppa:ondrej/php这些 PPA 源会以.list文件的形式保存在/etc/apt/sources.list.d/目录下与 DEB822 格式的.sources文件共存。