Ubuntu 24.04 更换国内软件源指南 | 2026年3月26日

Ubuntu 24.04 更换国内软件源指南

系统信息确认

  • 首先确认系统版本是否为 Ubuntu 24.04:
bash 复制代码
lsb_release -a
预期输出应包含:

Release: 24.04
Codename: noble

一、备份原始源文件
在进行任何修改前,务必备份原始源文件:

bash 复制代码
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

二、国内镜像源列表

  • 以下是适用于 Ubuntu 24.04 (Noble) 的国内镜像源,选择其中一个使用即可。
  1. 阿里云镜像源
bash 复制代码
deb http://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
  1. 清华大学镜像源
bash 复制代码
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse
  1. 中国科学技术大学镜像源
bash 复制代码
deb https://mirrors.ustc.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ noble-security main restricted universe multiverse
  1. 网易镜像源
bash 复制代码
deb http://mirrors.163.com/ubuntu/ noble main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ noble-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ noble-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ noble-backports main restricted universe multiverse
  1. 华为云镜像源
bash 复制代码
deb https://mirrors.huaweicloud.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.huaweicloud.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.huaweicloud.com/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.huaweicloud.com/ubuntu/ noble-security main restricted universe multiverse

三、换源方法
方法一:手动编辑(推荐)

编辑源文件:

bash 复制代码
sudo nano /etc/apt/sources.list

清空文件内容(按 Ctrl+K 逐行删除,或直接清空)

粘贴所选镜像源的配置内容

保存并退出:

Ctrl + O 保存

Enter 确认

Ctrl + X 退出

方法二:使用 sed 命令一键替换(以阿里云为例)

替换官方源为阿里云镜像源

bash 复制代码
sudo sed -i 's|http://archive.ubuntu.com/ubuntu/|http://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list
sudo sed -i 's|http://security.ubuntu.com/ubuntu/|http://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list

更新软件源

bash 复制代码
sudo apt update

方法三:使用 echo 重写文件

以阿里云为例

bash 复制代码
sudo tee /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
EOF

更新软件源

bash 复制代码
sudo apt update

四、更新系统

换源完成后,执行以下命令更新软件包列表:

bash 复制代码
sudo apt update

如需要升级所有已安装软件包:

bash 复制代码
sudo apt upgrade -y

五、验证换源是否成功

检查源文件内容:

bash 复制代码
cat /etc/apt/sources.list

观察更新速度:再次运行 sudo apt update,如果下载速度明显提升,说明换源成功

六、恢复官方源

如需恢复官方源,执行以下命令:

bash 复制代码
sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
sudo apt update

七、常见问题

Q1: 更新时出现 GPG 错误?

解决方案:导入缺失的 GPG 密钥

bash 复制代码
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys [密钥ID]

Q2: 换源后速度没有提升?

解决方案:

尝试更换其他镜像源

使用 ping 命令测试到镜像源的延迟

检查网络连接是否正常

Q3: 如何选择最适合的镜像源?

地理位置:选择离你最近的镜像源

网络运营商:部分镜像源对特定运营商有优化

速度测试:可尝试多个镜像源,通过 apt update 的速度对比选择

八、镜像源说明

bash 复制代码
源类型	说明
main	Ubuntu 官方支持的自由软件
restricted	设备专有驱动
universe	社区维护的自由软件
multiverse	非自由软件
updates	软件更新
security	安全更新
backports	向后移植的软件
proposed	预发布更新(通常不建议启用)

注意事项:

务必先备份原始源文件

选择离你地理位置较近的镜像源可获得更快的下载速度

生产环境建议分步执行命令,观察每一步的输出结果

相关推荐
xinyu3916 小时前
旧版Ubuntu Docker镜像 apt 失败
linux·ubuntu·docker
JZC_xiaozhong7 小时前
OA调价审批后,采购调价单如何自动同步到ERP?解决漏录错价难题
大数据·linux·服务器·前端·数据库·数据孤岛解决方案·数据集成与应用集成
ljs6482739517 小时前
Linux 实用命令:环境变量、文件传输、压缩解压、跨服务器传文件
linux·运维·服务器
AliCloudROS7 小时前
一次真实录屏:我只说每月别超过 200 块,小程序后端就搭好了
运维·人工智能·云计算
__Witheart__7 小时前
lunch选择的版型与版型对应的配置文件
android·linux
A小调的码农7 小时前
给垃圾平板“一生E本” 装新系统—————Armbian 编译 KYX T7Y (RK3326) 踩坑全记录
linux·嵌入式硬件
ljs6482739517 小时前
Linux 网络常用命令与端口基础详解
linux·网络·php
蓝狐社7 小时前
一张被低估的芯片版图——中兴通讯
运维·服务器
hanxiuchao8 小时前
告别客户端臃肿!网页端 M3U8 播放调试方案,适配全办公场景
运维·python·django·m3u8·m3u8播放
qq_163135758 小时前
Linux 判断是否安装 Conda / Miniconda 完整方法
linux