Linux

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > Linux > Ubuntu24.04配置国内源

Ubuntu24.04配置国内源的操作步骤

作者:洛小豆

Ubuntu 24.04 LTS(代号 Noble Numbat)作为最新的长期支持版本,在国内使用时经常遇到两个常见问题:软件包下载速度慢,所以本文我主要是整理一下配置国内源的操作步骤,需要的朋友可以参考下

配置国内镜像源

为什么需要配置国内镜像源?

Ubuntu 默认使用官方源服务器(通常位于海外),在国内访问时会遇到以下问题:

配置国内镜像源后,大幅改善使用体验。

常见的国内镜像源

国内主要的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

软件仓库组件说明

四、更新软件包缓存

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配置国内源内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文