配置国内镜像源
为什么需要配置国内镜像源?
ubuntu 默认使用官方源服务器(通常位于海外),在国内访问时会遇到以下问题:
- 下载速度极慢,经常只有几kb/s
- 网络连接不稳定,容易中断
- 高峰时段访问困难
- 影响系统更新和软件安装效率
配置国内镜像源后,大幅改善使用体验。
常见的国内镜像源
国内主要的ubuntu镜像源包括:
- 阿里云镜像:mirrors.aliyun.com/ubuntu/
- 清华大学镜像:mirrors.tuna.tsinghua.edu.cn/ubuntu/
- 中科大镜像:mirrors.ustc.edu.cn/ubuntu/
- 华为云镜像:mirrors.huaweicloud.com/ubuntu/
本指南以阿里云镜像为例
操作步骤
一、备份原有源列表
修改任何系统配置文件之前,备份是必不可少的步骤! 这是系统管理的基本原则。
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
备份完成后,可以通过以下命令验证备份文件:
ls -la /etc/apt/sources.list*
如果出现问题,可以随时恢复:
sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
二、查看当前系统版本
确认系统版本信息,确保使用正确的源配置:
lsb_release -a cat /etc/os-release
ubuntu 24.04的代号是"noble",这在配置源时很重要。
三、更换为阿里云镜像源
方法一:使用sed命令批量替换
sudo sed -i 's|http://.*archive.ubuntu.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list sudo sed -i 's|http://.*security.ubuntu.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list
方法二:直接重写整个文件(推荐)
sudo tee /etc/apt/sources.list <<-'eof' # 阿里云 ubuntu 24.04 lts 镜像源 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-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse eof
软件仓库组件说明
- main:官方支持的自由软件
- restricted:官方支持的非完全自由软件
- universe:社区维护的自由软件
- multiverse:非自由软件
四、更新软件包缓存
sudo apt update sudo apt upgrade -y
更新过程中如果看到类似以下输出,说明配置成功:
get:1 https://mirrors.aliyun.com/ubuntu noble inrelease [256 kb] get:2 https://mirrors.aliyun.com/ubuntu noble-updates inrelease [126 kb]
五、验证源配置
检查下载速度是否有明显提升:
sudo apt install htop
如果安装速度明显变快,说明配置成功。
到此这篇关于ubuntu24.04配置国内源的操作步骤的文章就介绍到这了,更多相关ubuntu24.04配置国内源内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论