一、CentOS、RHEL、Fedora
CentOS 8(非 Stream 版本)已被官方移除出该仓库。如有需要,请使用 centos-vault 镜像。CentOS 9 Stream 及以后的版本的镜像位于 centos-stream。
CentOS Stream 9 默认启用了包管理工具 dnf,其是 yum 包管理工具的替代品。dnf 与 yum 大部分的命令都是通用的,dnf 也使用 /etc/yum.repos.d/
进行镜像配置。
CentOS Stream 9 中源被整合入两个文件 centos.repo
和 centos-addons.repo
,由于文件中不包含 baseurl
字段,需要手动插入,通过文本替换修改源的方法较为复杂,也可以选择直接复制最后的替换结果覆盖源文件。
2.1 对于 CentOS 9 Stream,使用以下命令替换默认的配置
#备份配置文件
cp -rf /etc/yum.repos.d/centos.repo /etc/yum.repos.d/centos.repo.backup
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/centos.repo
2.2 对于 CentOS 8 Stream,使用以下命令替换默认的配置
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-Stream-AppStream.repo \
/etc/yum.repos.d/CentOS-Stream-BaseOS.repo \
/etc/yum.repos.d/CentOS-Stream-Extras.repo \
/etc/yum.repos.d/CentOS-Stream-PowerTools.repo
2.3 对于 CentOS 7,使用以下命令替换默认配置
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-Base.repo
2.4 对于 CentOS 8,使用以下命令替换默认配置
sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
以上命令只替换了默认启用的仓库。
2.5 Fedora>=39
sudo sed -e 's|^metalink=|#metalink=|g' \
-e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.ustc.edu.cn/fedora|g' \
-i.bak \
/etc/yum.repos.d/fedora.repo \
/etc/yum.repos.d/fedora-updates.repo
2.6 Fedora <=38
sudo sed -e 's|^metalink=|#metalink=|g' \
-e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.ustc.edu.cn/fedora|g' \
-i.bak \
/etc/yum.repos.d/fedora.repo \
/etc/yum.repos.d/fedora-modular.repo \
/etc/yum.repos.d/fedora-updates.repo \
/etc/yum.repos.d/fedora-updates-modular.repo
2.6 以上所有修改软件源替换修改完成后,清除并重建缓存:请运行 命令更新缓存。
# 使用 dnf
dnf clean all && dnf makecache
# 或使用 yum
yum clean all && yum makecache
二、Debian
2.1 Debian 档案库参数说明
对于系统用户,是使用 APT 系统来访问 Debian 档案库,源列表有单上格式和deb822格式两种形式,自新版本的 Debian 12与 Ubuntu 24.04 起,默认预装的系统中 APT 的系统源配置文件不再是传统的 /etc/apt/sources.list
。
单行格式的源列表如下:
deb http://deb.debian.org/debian/ bookworm main non-free-firmware contrib non-free
deb-src http://deb.debian.org/debian/ bookworm main non-free-firmware contrib non-free
deb http://security.debian.org/debian-security bookworm-security main non-free-firmware contrib non-free
deb-src http://security.debian.org/debian-security bookworm-security main non-free-firmware contrib non-free
- 它的定义文件在"
/etc/apt/sources.list
"文件和"/etc/apt/sources.list.d/*.list
"文件里面。-
每一行定义了 APT 系统的数据源。
-
“
deb
” 的那行定义了二进制软件包。 -
“
deb-src
” 的那行定义了源代码软件包。 -
第一个参数是 Debian 档案库的根 URL 。
-
第二个参数是发行版名称,可以使用套件名或代号。
-
第三个和之后的参数是 Debian 档案库的有效档案库范围名称。
-
新的 DEB822 格式自 APT 1.1(2015 年发布)起支持,后缀为 .sources
,存储在 /etc/apt/sources.list.d/
目录下,
使用 deb822 格式的源列表如下:
Types: deb deb-src
URIs: http://deb.debian.org/debian/
Suites: bookworm
Components: main non-free-firmware contrib non-free
Types: deb deb-src
URIs: http://security.debian.org/debian-security/
Suites: bookworm-security
Components: main non-free-firmware contrib non-free
-
它的定义文件在"
/etc/apt/sources.list.d/*.source
"文件里。 -
由空格隔开的每个多行块,定义了 APT 系统的数据源。
-
"
Types:
" 章节定义列表类型,即"deb
" 和 "deb-src
"。 -
"
URIs:
"章节定义 Debian 档案库 URI 的根地址。 -
"
Suites:
"章节定义了发行版名称列表,名称可以使用套件名或代号。 -
"
Components:
" 章节定义 Debian 档案库中有效档案库名称列表。
如果只是用 aptitude
,它不访问源代码相关的元数据,“deb-src
”定义可以安全地省略。这可以加速档案库元数据的更新。URL 可以是 "https://
", "http://
", "ftp://
", "file://
",……
"#
" 开头的行是注释,被忽略。
这里,建议使用codename代码名,如:“bookworm
”或"trixie
"来代替套件名“stable
”或"testing
" ,以避免下一个 stable
版本发布时出现意外。
2.2 参数配置
一般情况下,将 /etc/apt/sources.list
或 /etc/apt/sources.list.d/debian.sources
文件中 Debian 默认的源地址 http://deb.debian.org/
替换为新的软件源地址,如: http://mirrors.ustc.edu.cn
即可。可供使用的国内软件源地址有很多,详见第三章。
Debian12
单行格式
# 默认注释了源码仓库,如有需要可自行取消注释
deb http://mirrors.ustc.edu.cn/debian bookworm main contrib non-free non-free-firmware
# deb-src http://mirrors.ustc.edu.cn/debian bookworm main contrib non-free non-free-firmware
deb http://mirrors.ustc.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware
# deb-src http://mirrors.ustc.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware
# backports 软件源,请按需启用
# deb http://mirrors.ustc.edu.cn/debian bookworm-backports main contrib non-free non-free-firmware
# deb-src http://mirrors.ustc.edu.cn/debian bookworm-backports main contrib non-free non-free-firmware
deb822 格式
Types: deb
URIs: http://mirrors.ustc.edu.cn/debian
Suites: bookworm bookworm-updates
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
Types: deb
URIs: http://mirrors.ustc.edu.cn/debian-security
Suites: bookworm-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
2.3 执行脚本
修改软件源地址后,执行以下脚本:
#完全清除本地仓库的软件包检索文件
apt-get clean all
#更新软件包档案库元数据
apt-get update
三、国内软件源参考
ftp.cn.debian.org,
mirrors.ustc.edu.cn
mirror.lzu.edu.cn
mirrors.163.com:
阿里源:developer.aliyun.com/mirror/centos
清华源:https://mirrors.tuna.tsinghua.edu.cn/
腾讯源:https://mirrors.cloud.tencent.com/
华为源:https://mirrors.huaweicloud.com/home
参考链接:
mirrors.ustc.edu.cn/help/