阿里云的镜像源可以显著提升国内用户安装和更新软件包的速度。以下是针对常见操作系统的详细配置教程。
1. 配置 CentOS 或 RHEL 系统的阿里云 Yum 源
步骤:
-
备份原有的源文件:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
-
下载阿里云的 CentOS 源配置文件:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
如果你使用的是其他版本,请根据以下列表替换:
- CentOS 8:
https://mirrors.aliyun.com/repo/Centos-8.repo
- CentOS 9:
https://mirrors.aliyun.com/repo/Centos-stream-9.repo
- CentOS 8:
-
清理缓存并生成缓存信息:
yum clean all yum makecache
2. 配置 Ubuntu/Debian 系统的阿里云 Apt 源
步骤:
-
备份原有的源文件:
cp /etc/apt/sources.list /etc/apt/sources.list.bak
-
编辑
/etc/apt/sources.list
文件:nano /etc/apt/sources.list
将原有内容替换为以下内容(根据你的系统版本调整
VERSION
):Ubuntu 示例:
deb http://mirrors.aliyun.com/ubuntu/ VERSION main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ VERSION-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ VERSION-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ VERSION-backports main restricted universe multiverse
替换
VERSION
:- 20.04 (Focal):
focal
- 22.04 (Jammy):
jammy
Debian 示例:
deb http://mirrors.aliyun.com/debian/ VERSION main contrib non-free deb http://mirrors.aliyun.com/debian/ VERSION-updates main contrib non-free deb http://mirrors.aliyun.com/debian-security/ VERSION-security main contrib non-free
替换
VERSION
:- Debian 10:
buster
- Debian 11:
bullseye
- 20.04 (Focal):
-
更新系统缓存:
apt update
3. 配置阿里云 Docker 源
步骤:
-
创建或修改
/etc/docker/daemon.json
文件:mkdir -p /etc/docker nano /etc/docker/daemon.json
添加以下内容:
{ "registry-mirrors": ["https://registry.aliyuncs.com"] }
-
重启 Docker 服务:
systemctl daemon-reload systemctl restart docker
其他说明
-
如果你使用的是其他发行版(如 Arch Linux、Fedora)或者需要配置其他工具(如 pip),可以参考阿里云官方的镜像站点:https://developer.aliyun.com/mirror。
-
配置完成后,请定期检查源的有效性,确保持续获得快速和可靠的服务。