新手必看:轻松替换 AlmaLinux 镜像源,告别网络不畅,提升系统更新速度

2026-09-17 0 阅读

在现代信息化的社会中,Linux 系统因其稳定性和安全性被广泛应用于服务器和桌面领域。AlmaLinux 作为 CentOS 的继任者,以其兼容性和易用性受到许多用户的喜爱。然而,由于地域差异,部分用户可能会遇到网络连接不畅、镜像源不稳定等问题,导致系统更新速度缓慢。今天,就让我来为大家介绍如何轻松替换 AlmaLinux 的镜像源,告别网络不畅,提升系统更新速度。

1. 了解镜像源

镜像源,即软件仓库,是 Linux 系统中存放软件包的地方。用户可以通过镜像源下载所需的软件包,进行系统更新。常见的镜像源有阿里云、网易、华为等。

2. 查看当前镜像源

在替换镜像源之前,我们先来查看一下当前 AlmaLinux 系统所使用的镜像源。打开终端,输入以下命令:

dnf repolist enabled

执行上述命令后,你会看到当前系统所使用的镜像源及其相关信息。

3. 替换镜像源

接下来,我们将替换 AlmaLinux 系统的镜像源。以下以替换为阿里云镜像源为例:

3.1 替换 baseos 镜像源

打开终端,输入以下命令:

sudo mv /etc/yum.repos.d/baseos.repo /etc/yum.repos.d/baseos.repo.bak

执行上述命令后,备份原镜像源配置文件。

然后,创建新的镜像源配置文件:

sudo nano /etc/yum.repos.d/baseos.repo

在打开的文件中,粘贴以下内容:

[baseos]
name=AlmaLinux $releasever - BaseOS
baseurl=https://mirrors.aliyun.com/almaLinux/centos/$releasever/BaseOS/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/almaLinux/centos/RPM-GPG-KEY-almaLinux-$releasever

保存并关闭文件。

3.2 替换 extras 镜像源

重复上述步骤,替换 extras 镜像源:

sudo mv /etc/yum.repos.d/extras.repo /etc/yum.repos.d/extras.repo.bak
sudo nano /etc/yum.repos.d/extras.repo

在打开的文件中,粘贴以下内容:

[extras]
name=AlmaLinux $releasever - Extras
baseurl=https://mirrors.aliyun.com/almaLinux/centos/$releasever/Extras/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/almaLinux/centos/RPM-GPG-KEY-almaLinux-$releasever

保存并关闭文件。

3.3 替换 AppStream 镜像源

sudo mv /etc/yum.repos.d/appstream.repo /etc/yum.repos.d/appstream.repo.bak
sudo nano /etc/yum.repos.d/appstream.repo

在打开的文件中,粘贴以下内容:

[appstream]
name=AlmaLinux $releasever - AppStream
baseurl=https://mirrors.aliyun.com/almaLinux/centos/$releasever/AppStream/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/almaLinux/centos/RPM-GPG-KEY-almaLinux-$releasever

保存并关闭文件。

4. 重启 yum

为了使新的镜像源生效,我们需要重启 yum:

sudo systemctl restart yum

5. 验证替换结果

最后,我们验证一下替换后的镜像源是否成功:

dnf repolist enabled

如果看到新的镜像源信息,说明替换成功。

总结

通过以上步骤,你就可以轻松替换 AlmaLinux 的镜像源,告别网络不畅,提升系统更新速度。当然,你也可以根据自己的需求,选择其他镜像源进行替换。希望这篇文章能对你有所帮助。

分享到: