Ubuntu 24.04/26.04 更换国内镜像源教程
前言
Ubuntu系统默认使用官方源,在国内访问时速度较慢,有时甚至无法连接。本文介绍如何将Ubuntu系统更换为国内镜像源,以提升软件包下载速度。
注意:Ubuntu 24.04 是当前最新的LTS版本,26.04预计于2026年发布。本文方法适用于两者。
适用系统
- Ubuntu 24.04 LTS
- Ubuntu 26.04 LTS(发布后)
- 基于Ubuntu的发行版(如Linux Mint、elementary OS等)
国内常用镜像源
阿里云镜像源
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
清华镜像源
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
华为云镜像源
deb https://repo.huaweicloud.com/ubuntu/ noble main restricted universe multiverse
deb https://repo.huaweicloud.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://repo.huaweicloud.com/ubuntu/ noble-backports main restricted universe multiverse
deb https://repo.huaweicloud.com/ubuntu/ noble-security main restricted universe multiverse
更换步骤
1. 备份原有源列表
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
2. 查看当前Ubuntu版本代号
lsb_release -a
输出示例:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04 LTS
Release: 24.04
Codename: noble
重要:记录下Codename(如noble、jammy等),后续配置需要用到。
3. 替换国内源
方法一:使用sed命令直接替换
以阿里云为例,将官方源替换为阿里云源:
sudo sed -i 's|http://archive.ubuntu.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list
方法二:手动编辑sources.list
sudo nano /etc/apt/sources.list
将文件内容全部替换为选择好的国内源地址,保存退出。
4. 更新软件包列表
sudo apt update
如果过程中出现签名错误,可以尝试执行:
sudo apt install apt-transport-https ca-certificates
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 签名ID
5. 升级系统(可选)
sudo apt upgrade
常见问题
Q1: 更换源后更新失败怎么办?
- 检查网络连接是否正常
- 确认源地址是否正确
- 尝试更换其他国内镜像源
- 恢复备份:
sudo cp /etc/apt/sources.list.backup /etc/apt/sources.list
Q2: 如何查看是否更换成功?
执行 sudo apt update,观察下载源地址是否已变更。
Q3: Ubuntu版本代号如何获取?
使用 lsb_release -a 命令查看,Codename即为版本代号。
总结
更换国内镜像源可以显著提升Ubuntu系统的软件包下载速度,推荐使用阿里云、清华或华为云等国内知名镜像源。如果遇到问题,及时恢复备份文件即可。
参考文档:
– 阿里云Ubuntu镜像
– 清华大学Ubuntu镜像
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END












暂无评论内容