ANALYSIS
常用国内镜像源
阿里云镜像源
清华大学镜像源
- Fedora: https://mirrors.tuna.tsinghua.edu.cn/fedora/
- Updates: https://mirrors.tuna.tsinghua.edu.cn/fedora/updates/
中科大镜像源
网易镜像源
上海交大镜像源
换源方法
方法 1: 使用 sed 命令快速换源 ( 推荐 )
备份原有配置
PRTCL // BASH
sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.backup更换为阿里云源
PRTCL // BASH
sudo sed -e 's|^metalink=|#metalink=|g' \ -e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.aliyun.com/fedora|g' \ -i.bak \ /etc/yum.repos.d/fedora.repo \ /etc/yum.repos.d/fedora-updates.repo更换为清华源
PRTCL // BASH
sudo sed -e 's|^metalink=|#metalink=|g' \ -e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora|g' \ -i.bak \ /etc/yum.repos.d/fedora.repo \ /etc/yum.repos.d/fedora-updates.repo更换为中科大源
PRTCL // BASH
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更新缓存
PRTCL // BASH
sudo dnf makecache方法 2: 手动编辑配置文件
第一步: 备份原有配置
PRTCL // BASH
sudo cp /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.baksudo cp /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.bak第二步: 编辑 fedora.repo
PRTCL // BASH
sudo nano /etc/yum.repos.d/fedora.repo注释掉metalink=开头的行,取消注释baseurl=行并修改为镜像源地址。
阿里云源配置示例:
PRTCL // INI
[fedora]name=Fedora $releasever - $basearch#metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearchbaseurl=https://mirrors.aliyun.com/fedora/releases/$releasever/Everything/$basearch/os/enabled=1countme=1metadata_expire=7drepo_gpgcheck=0type=rpmgpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearchskip_if_unavailable=False清华源配置示例:
PRTCL // INI
[fedora]name=Fedora $releasever - $basearch#metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearchbaseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/releases/$releasever/Everything/$basearch/os/enabled=1countme=1metadata_expire=7drepo_gpgcheck=0type=rpmgpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearchskip_if_unavailable=False中科大源配置示例:
PRTCL // INI
[fedora]name=Fedora $releasever - $basearch#metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearchbaseurl=https://mirrors.ustc.edu.cn/fedora/releases/$releasever/Everything/$basearch/os/enabled=1countme=1metadata_expire=7drepo_gpgcheck=0type=rpmgpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearchskip_if_unavailable=False第三步: 编辑 fedora-updates.repo
PRTCL // BASH
sudo nano /etc/yum.repos.d/fedora-updates.repo阿里云源配置示例:
PRTCL // INI
[updates]name=Fedora $releasever - $basearch - Updates#metalink=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearchbaseurl=https://mirrors.aliyun.com/fedora/updates/$releasever/Everything/$basearch/enabled=1countme=1repo_gpgcheck=0type=rpmgpgcheck=1metadata_expire=6hgpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearchskip_if_unavailable=False清华源配置示例:
PRTCL // INI
[updates]name=Fedora $releasever - $basearch - Updates#metalink=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearchbaseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/updates/$releasever/Everything/$basearch/enabled=1countme=1repo_gpgcheck=0type=rpmgpgcheck=1metadata_expire=6hgpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearchskip_if_unavailable=False中科大源配置示例:
PRTCL // INI
[updates]name=Fedora $releasever - $basearch - Updates#metalink=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearchbaseurl=https://mirrors.ustc.edu.cn/fedora/updates/$releasever/Everything/$basearch/enabled=1countme=1repo_gpgcheck=0type=rpmgpgcheck=1metadata_expire=6hgpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearchskip_if_unavailable=False第四步: 编辑 fedora-modular.repo( 如果存在 )
PRTCL // BASH
sudo nano /etc/yum.repos.d/fedora-modular.repo修改方式与上述相同,将 baseurl 改为对应镜像源。
阿里云源:
PRTCL // INI
[fedora-modular]name=Fedora Modular $releasever - $basearch#metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-modular-$releasever&arch=$basearchbaseurl=https://mirrors.aliyun.com/fedora/releases/$releasever/Modular/$basearch/os/enabled=1metadata_expire=7drepo_gpgcheck=0type=rpmgpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearchskip_if_unavailable=False第五步: 编辑 fedora-updates-modular.repo( 如果存在 )
PRTCL // BASH
sudo nano /etc/yum.repos.d/fedora-updates-modular.repo阿里云源:
PRTCL // INI
[updates-modular]name=Fedora Modular $releasever - $basearch - Updates#metalink=https://mirrors.fedoraproject.org/metalink?repo=updates-released-modular-f$releasever&arch=$basearchbaseurl=https://mirrors.aliyun.com/fedora/updates/$releasever/Modular/$basearch/enabled=1repo_gpgcheck=0type=rpmgpgcheck=1metadata_expire=6hgpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearchskip_if_unavailable=False第六步: 更新缓存
PRTCL // BASH
sudo dnf clean allsudo dnf makecache方法 3: 使用 dnf config-manager
禁用 metalink,启用 baseurl
PRTCL // BASH
sudo dnf config-manager --set-disabled fedorasudo dnf config-manager --set-disabled updates添加新源
PRTCL // BASH
sudo dnf config-manager --add-repo https://mirrors.aliyun.com/fedora/更新缓存
PRTCL // BASH
sudo dnf makecache验证换源成功
查看当前源配置
PRTCL // BASH
cat /etc/yum.repos.d/fedora.repocat /etc/yum.repos.d/fedora-updates.repo测试下载速度
PRTCL // BASH
sudo dnf makecache观察下载速度,应该明显提升。
查看源列表
PRTCL // BASH
dnf repolist安装测试软件
PRTCL // BASH
sudo dnf install neofetch -y如果安装速度很快,说明换源成功。
恢复默认源
恢复备份
PRTCL // BASH
sudo cp /etc/yum.repos.d.backup/* /etc/yum.repos.d/sudo dnf clean allsudo dnf makecache或手动恢复
编辑配置文件,取消注释metalink=行,注释掉baseurl=行:
PRTCL // BASH
sudo nano /etc/yum.repos.d/fedora.reposudo nano /etc/yum.repos.d/fedora-updates.repo恢复为:
PRTCL // INI
[fedora]name=Fedora $releasever - $basearchmetalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch#baseurl=https://mirrors.aliyun.com/fedora/releases/$releasever/Everything/$basearch/os/enabled=1...更新缓存:
PRTCL // BASH
sudo dnf clean allsudo dnf makecache一键换源脚本
阿里云源脚本
创建脚本文件:
PRTCL // BASH
nano change-to-aliyun.sh添加以下内容:
PRTCL // BASH
#!/bin/bash
# 备份原有配置sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.backup.$(date +%Y%m%d)
# 更换为阿里云源sudo sed -e 's|^metalink=|#metalink=|g' \ -e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.aliyun.com/fedora|g' \ -i.bak \ /etc/yum.repos.d/fedora.repo \ /etc/yum.repos.d/fedora-updates.repo
# 如果存在 modular 源也一并更换if [ -f /etc/yum.repos.d/fedora-modular.repo ]; then sudo sed -e 's|^metalink=|#metalink=|g' \ -e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.aliyun.com/fedora|g' \ -i.bak \ /etc/yum.repos.d/fedora-modular.repo \ /etc/yum.repos.d/fedora-updates-modular.repofi
# 清理并重建缓存sudo dnf clean allsudo dnf makecache
echo "已成功更换为阿里云镜像源!"赋予执行权限并运行:
PRTCL // BASH
chmod +x change-to-aliyun.sh./change-to-aliyun.sh清华源脚本
PRTCL // BASH
#!/bin/bash
sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.backup.$(date +%Y%m%d)
sudo sed -e 's|^metalink=|#metalink=|g' \ -e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora|g' \ -i.bak \ /etc/yum.repos.d/fedora.repo \ /etc/yum.repos.d/fedora-updates.repo
if [ -f /etc/yum.repos.d/fedora-modular.repo ]; then sudo sed -e 's|^metalink=|#metalink=|g' \ -e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora|g' \ -i.bak \ /etc/yum.repos.d/fedora-modular.repo \ /etc/yum.repos.d/fedora-updates-modular.repofi
sudo dnf clean allsudo dnf makecache
echo "已成功更换为清华大学镜像源!"更换第三方源
RPM Fusion 源换源
RPM Fusion 提供 Fedora 官方不包含的软件包。
启用 RPM Fusion
PRTCL // BASH
sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpmsudo dnf install https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm更换为清华源
PRTCL // BASH
sudo sed -e 's|^metalink=|#metalink=|g' \ -e 's|^#baseurl=https://download1.rpmfusion.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn/rpmfusion|g' \ -i.bak \ /etc/yum.repos.d/rpmfusion-*.repo更换为中科大源
PRTCL // BASH
sudo sed -e 's|^metalink=|#metalink=|g' \ -e 's|^#baseurl=https://download1.rpmfusion.org|baseurl=https://mirrors.ustc.edu.cn/rpmfusion|g' \ -i.bak \ /etc/yum.repos.d/rpmfusion-*.repo更新缓存
PRTCL // BASH
sudo dnf makecacheCisco OpenH264 源换源
编辑配置文件:
PRTCL // BASH
sudo nano /etc/yum.repos.d/fedora-cisco-openh264.repo修改为:
PRTCL // INI
[fedora-cisco-openh264]name=Fedora $releasever openh264 (From Cisco) - $basearch#metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-cisco-openh264-$releasever&arch=$basearchbaseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/openh264/$releasever/$basearch/enabled=1metadata_expire=14dtype=rpmrepo_gpgcheck=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearchskip_if_unavailable=True其他软件源配置
Docker 源换源
添加 Docker 仓库
PRTCL // BASH
sudo dnf config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/fedora/docker-ce.repo或手动编辑
PRTCL // BASH
sudo nano /etc/yum.repos.d/docker-ce.repoPRTCL // INI
[docker-ce-stable]name=Docker CE Stable - $basearchbaseurl=https://mirrors.aliyun.com/docker-ce/linux/fedora/$releasever/$basearch/stableenabled=1gpgcheck=1gpgkey=https://mirrors.aliyun.com/docker-ce/linux/fedora/gpg安装 Docker
PRTCL // BASH
sudo dnf install docker-ce docker-ce-cli containerd.io -y配置 Docker 镜像加速
PRTCL // BASH
sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json <<-'EOF'{ "registry-mirrors": [ "https://docker.mirrors.ustc.edu.cn", "https://hub-mirror.c.163.com", "https://mirror.ccs.tencentyun.com" ]}EOFsudo systemctl daemon-reloadsudo systemctl restart dockerPython pip 换源
临时使用
PRTCL // BASH
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple <package>永久配置
PRTCL // BASH
mkdir -p ~/.pipcat > ~/.pip/pip.conf <<EOF[global]index-url = https://pypi.tuna.tsinghua.edu.cn/simple[install]trusted-host = pypi.tuna.tsinghua.edu.cnEOF或使用 pip 命令配置
PRTCL // BASH
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simpleNode.js npm 换源
临时使用
PRTCL // BASH
npm install --registry=https://registry.npmmirror.com <package>永久配置
PRTCL // BASH
npm config set registry https://registry.npmmirror.com验证
PRTCL // BASH
npm config get registry或使用 cnpm
PRTCL // BASH
npm install -g cnpm --registry=https://registry.npmmirror.comcnpm install <package>Rust Cargo 换源
编辑配置文件:
PRTCL // BASH
mkdir -p ~/.cargonano ~/.cargo/config添加:
PRTCL // TOML
[source.crates-io]replace-with = 'tuna'
[source.tuna]registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"或使用中科大源:
PRTCL // TOML
[source.crates-io]replace-with = 'ustc'
[source.ustc]registry = "https://mirrors.ustc.edu.cn/crates.io-index"DNF 配置优化
加速 DNF 下载
编辑 DNF 配置:
PRTCL // BASH
sudo nano /etc/dnf/dnf.conf添加以下配置:
PRTCL // INI
# 最大并行下载数max_parallel_downloads=10
# 启用最快镜像选择fastestmirror=True
# 增加超时时间timeout=60
# 启用增量下载deltarpm=True
# 保留缓存keepcache=True清理缓存
PRTCL // BASH
sudo dnf clean all重建缓存
PRTCL // BASH
sudo dnf makecache --refresh常见问题
更新时出现 GPG 签名错误
PRTCL // BASH
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$(rpm -E %fedora)-$(uname -m)或临时跳过 GPG 检查:
PRTCL // BASH
sudo dnf install --nogpgcheck <package>无法连接到镜像源
检查网络连接:
PRTCL // BASH
ping mirrors.aliyun.com尝试更换其他镜像源。
更新速度仍然很慢
- 尝试更换其他镜像源
- 检查本地网络状况
- 优化 DNF 配置 ( 参考上文 )
- 使用
axel或aria2加速下载
安装 axel:
PRTCL // BASH
sudo dnf install axel -y配置 DNF 使用 axel:
PRTCL // BASH
sudo nano /etc/dnf/dnf.conf添加:
PRTCL // INI
pluginpath=/usr/lib/python3.*/site-packages/dnf-plugins提示”仓库元数据已过期”
强制刷新元数据:
PRTCL // BASH
sudo dnf clean metadatasudo dnf makecache --refresh某些软件包找不到
检查是否启用了必要的仓库:
PRTCL // BASH
dnf repolist --all启用禁用的仓库:
PRTCL // BASH
sudo dnf config-manager --set-enabled <repo-name>更换源后无法更新
检查配置文件语法:
PRTCL // BASH
sudo dnf repolist如果报错,检查 repo 文件格式是否正确。
恢复备份:
PRTCL // BASH
sudo cp /etc/yum.repos.d.backup/* /etc/yum.repos.d/推荐镜像源选择
教育网用户
推荐使用教育网镜像:
- 清华大学镜像源 ( 速度快,稳定 )
- 中科大镜像源 ( 速度快 )
- 上海交大镜像源
电信用户
推荐使用:
- 阿里云镜像源 ( 速度快,稳定 )
- 网易镜像源
联通 / 移动用户
推荐使用:
- 阿里云镜像源
- 腾讯云镜像源
海外用户
使用官方源或就近的区域镜像。
镜像源速度测试
使用 dnf-plugins-core 测试
PRTCL // BASH
sudo dnf install dnf-plugins-core -ysudo dnf config-manager --set-enabled fastestmirror手动测试下载速度
PRTCL // BASH
time wget -O /dev/null https://mirrors.aliyun.com/fedora/releases/39/Everything/x86_64/os/repodata/repomd.xmltime wget -O /dev/null https://mirrors.tuna.tsinghua.edu.cn/fedora/releases/39/Everything/x86_64/os/repodata/repomd.xmltime wget -O /dev/null https://mirrors.ustc.edu.cn/fedora/releases/39/Everything/x86_64/os/repodata/repomd.xml比较下载时间,选择最快的源。
系统升级注意事项
升级 Fedora 版本
在升级 Fedora 版本前,建议恢复为官方源:
PRTCL // BASH
sudo cp /etc/yum.repos.d.backup/* /etc/yum.repos.d/sudo dnf clean allsudo dnf upgrade --refresh升级完成后再次更换为镜像源。
或直接使用镜像源升级
PRTCL // BASH
sudo dnf upgrade --refreshsudo dnf install dnf-plugin-system-upgrade -ysudo dnf system-upgrade download --releasever=40sudo dnf system-upgrade reboot参考资料
R P
Rhine Lab Pioneer Division
Auth_Verified: 2026.04.08
Auth_Verified: 2026.04.08
