复制成功
请遵守本站许可
REPORT
Chapter_Post // Field_Report

Post_Ref: RL-FEDORA换源

2026.04.08

Fedora换源教程

Echo HaoRan
Echo HaoRan
ANALYSIS

常用国内镜像源#

阿里云镜像源#

清华大学镜像源#

中科大镜像源#

网易镜像源#

上海交大镜像源#

换源方法#

方法 1: 使用 sed 命令快速换源 ( 推荐 )#

备份原有配置#

PRTCL // BASH
Terminal window
sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.backup

更换为阿里云源#

PRTCL // BASH
Terminal window
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
Terminal window
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
Terminal window
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
Terminal window
sudo dnf makecache

方法 2: 手动编辑配置文件#

第一步: 备份原有配置#

PRTCL // BASH
Terminal window
sudo cp /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.bak
sudo cp /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.bak

第二步: 编辑 fedora.repo#

PRTCL // BASH
Terminal window
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=$basearch
baseurl=https://mirrors.aliyun.com/fedora/releases/$releasever/Everything/$basearch/os/
enabled=1
countme=1
metadata_expire=7d
repo_gpgcheck=0
type=rpm
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

清华源配置示例:

PRTCL // INI
[fedora]
name=Fedora $releasever - $basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/releases/$releasever/Everything/$basearch/os/
enabled=1
countme=1
metadata_expire=7d
repo_gpgcheck=0
type=rpm
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

中科大源配置示例:

PRTCL // INI
[fedora]
name=Fedora $releasever - $basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch
baseurl=https://mirrors.ustc.edu.cn/fedora/releases/$releasever/Everything/$basearch/os/
enabled=1
countme=1
metadata_expire=7d
repo_gpgcheck=0
type=rpm
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

第三步: 编辑 fedora-updates.repo#

PRTCL // BASH
Terminal window
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=$basearch
baseurl=https://mirrors.aliyun.com/fedora/updates/$releasever/Everything/$basearch/
enabled=1
countme=1
repo_gpgcheck=0
type=rpm
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

清华源配置示例:

PRTCL // INI
[updates]
name=Fedora $releasever - $basearch - Updates
#metalink=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/updates/$releasever/Everything/$basearch/
enabled=1
countme=1
repo_gpgcheck=0
type=rpm
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

中科大源配置示例:

PRTCL // INI
[updates]
name=Fedora $releasever - $basearch - Updates
#metalink=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch
baseurl=https://mirrors.ustc.edu.cn/fedora/updates/$releasever/Everything/$basearch/
enabled=1
countme=1
repo_gpgcheck=0
type=rpm
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

第四步: 编辑 fedora-modular.repo( 如果存在 )#

PRTCL // BASH
Terminal window
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=$basearch
baseurl=https://mirrors.aliyun.com/fedora/releases/$releasever/Modular/$basearch/os/
enabled=1
metadata_expire=7d
repo_gpgcheck=0
type=rpm
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

第五步: 编辑 fedora-updates-modular.repo( 如果存在 )#

PRTCL // BASH
Terminal window
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=$basearch
baseurl=https://mirrors.aliyun.com/fedora/updates/$releasever/Modular/$basearch/
enabled=1
repo_gpgcheck=0
type=rpm
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

第六步: 更新缓存#

PRTCL // BASH
Terminal window
sudo dnf clean all
sudo dnf makecache

方法 3: 使用 dnf config-manager#

禁用 metalink,启用 baseurl#

PRTCL // BASH
Terminal window
sudo dnf config-manager --set-disabled fedora
sudo dnf config-manager --set-disabled updates

添加新源#

PRTCL // BASH
Terminal window
sudo dnf config-manager --add-repo https://mirrors.aliyun.com/fedora/

更新缓存#

PRTCL // BASH
Terminal window
sudo dnf makecache

验证换源成功#

查看当前源配置#

PRTCL // BASH
Terminal window
cat /etc/yum.repos.d/fedora.repo
cat /etc/yum.repos.d/fedora-updates.repo

测试下载速度#

PRTCL // BASH
Terminal window
sudo dnf makecache

观察下载速度,应该明显提升。

查看源列表#

PRTCL // BASH
Terminal window
dnf repolist

安装测试软件#

PRTCL // BASH
Terminal window
sudo dnf install neofetch -y

如果安装速度很快,说明换源成功。

恢复默认源#

恢复备份#

PRTCL // BASH
Terminal window
sudo cp /etc/yum.repos.d.backup/* /etc/yum.repos.d/
sudo dnf clean all
sudo dnf makecache

或手动恢复#

编辑配置文件,取消注释metalink=行,注释掉baseurl=行:

PRTCL // BASH
Terminal window
sudo nano /etc/yum.repos.d/fedora.repo
sudo nano /etc/yum.repos.d/fedora-updates.repo

恢复为:

PRTCL // INI
[fedora]
name=Fedora $releasever - $basearch
metalink=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
Terminal window
sudo dnf clean all
sudo dnf makecache

一键换源脚本#

阿里云源脚本#

创建脚本文件:

PRTCL // BASH
Terminal window
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.repo
fi
# 清理并重建缓存
sudo dnf clean all
sudo dnf makecache
echo "已成功更换为阿里云镜像源!"

赋予执行权限并运行:

PRTCL // BASH
Terminal window
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.repo
fi
sudo dnf clean all
sudo dnf makecache
echo "已成功更换为清华大学镜像源!"

更换第三方源#

RPM Fusion 源换源#

RPM Fusion 提供 Fedora 官方不包含的软件包。

启用 RPM Fusion#

PRTCL // BASH
Terminal window
sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

更换为清华源#

PRTCL // BASH
Terminal window
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
Terminal window
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
Terminal window
sudo dnf makecache

Cisco OpenH264 源换源#

编辑配置文件:

PRTCL // BASH
Terminal window
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=$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/openh264/$releasever/$basearch/
enabled=1
metadata_expire=14d
type=rpm
repo_gpgcheck=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=True

其他软件源配置#

Docker 源换源#

添加 Docker 仓库#

PRTCL // BASH
Terminal window
sudo dnf config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/fedora/docker-ce.repo

或手动编辑#

PRTCL // BASH
Terminal window
sudo nano /etc/yum.repos.d/docker-ce.repo
PRTCL // INI
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/fedora/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/fedora/gpg

安装 Docker#

PRTCL // BASH
Terminal window
sudo dnf install docker-ce docker-ce-cli containerd.io -y

配置 Docker 镜像加速#

PRTCL // BASH
Terminal window
sudo mkdir -p /etc/docker
sudo 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"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

Python pip 换源#

临时使用#

PRTCL // BASH
Terminal window
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple <package>

永久配置#

PRTCL // BASH
Terminal window
mkdir -p ~/.pip
cat > ~/.pip/pip.conf <<EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
EOF

或使用 pip 命令配置#

PRTCL // BASH
Terminal window
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

Node.js npm 换源#

临时使用#

PRTCL // BASH
Terminal window
npm install --registry=https://registry.npmmirror.com <package>

永久配置#

PRTCL // BASH
Terminal window
npm config set registry https://registry.npmmirror.com

验证#

PRTCL // BASH
Terminal window
npm config get registry

或使用 cnpm#

PRTCL // BASH
Terminal window
npm install -g cnpm --registry=https://registry.npmmirror.com
cnpm install <package>

Rust Cargo 换源#

编辑配置文件:

PRTCL // BASH
Terminal window
mkdir -p ~/.cargo
nano ~/.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
Terminal window
sudo nano /etc/dnf/dnf.conf

添加以下配置:

PRTCL // INI
# 最大并行下载数
max_parallel_downloads=10
# 启用最快镜像选择
fastestmirror=True
# 增加超时时间
timeout=60
# 启用增量下载
deltarpm=True
# 保留缓存
keepcache=True

清理缓存#

PRTCL // BASH
Terminal window
sudo dnf clean all

重建缓存#

PRTCL // BASH
Terminal window
sudo dnf makecache --refresh

常见问题#

更新时出现 GPG 签名错误#

PRTCL // BASH
Terminal window
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$(rpm -E %fedora)-$(uname -m)

或临时跳过 GPG 检查:

PRTCL // BASH
Terminal window
sudo dnf install --nogpgcheck <package>

无法连接到镜像源#

检查网络连接:

PRTCL // BASH
Terminal window
ping mirrors.aliyun.com

尝试更换其他镜像源。

更新速度仍然很慢#

  • 尝试更换其他镜像源
  • 检查本地网络状况
  • 优化 DNF 配置 ( 参考上文 )
  • 使用axelaria2加速下载

安装 axel:

PRTCL // BASH
Terminal window
sudo dnf install axel -y

配置 DNF 使用 axel:

PRTCL // BASH
Terminal window
sudo nano /etc/dnf/dnf.conf

添加:

PRTCL // INI
pluginpath=/usr/lib/python3.*/site-packages/dnf-plugins

提示”仓库元数据已过期”#

强制刷新元数据:

PRTCL // BASH
Terminal window
sudo dnf clean metadata
sudo dnf makecache --refresh

某些软件包找不到#

检查是否启用了必要的仓库:

PRTCL // BASH
Terminal window
dnf repolist --all

启用禁用的仓库:

PRTCL // BASH
Terminal window
sudo dnf config-manager --set-enabled <repo-name>

更换源后无法更新#

检查配置文件语法:

PRTCL // BASH
Terminal window
sudo dnf repolist

如果报错,检查 repo 文件格式是否正确。

恢复备份:

PRTCL // BASH
Terminal window
sudo cp /etc/yum.repos.d.backup/* /etc/yum.repos.d/

推荐镜像源选择#

教育网用户#

推荐使用教育网镜像:

  • 清华大学镜像源 ( 速度快,稳定 )
  • 中科大镜像源 ( 速度快 )
  • 上海交大镜像源

电信用户#

推荐使用:

  • 阿里云镜像源 ( 速度快,稳定 )
  • 网易镜像源

联通 / 移动用户#

推荐使用:

  • 阿里云镜像源
  • 腾讯云镜像源

海外用户#

使用官方源或就近的区域镜像。

镜像源速度测试#

使用 dnf-plugins-core 测试#

PRTCL // BASH
Terminal window
sudo dnf install dnf-plugins-core -y
sudo dnf config-manager --set-enabled fastestmirror

手动测试下载速度#

PRTCL // BASH
Terminal window
time wget -O /dev/null https://mirrors.aliyun.com/fedora/releases/39/Everything/x86_64/os/repodata/repomd.xml
time wget -O /dev/null https://mirrors.tuna.tsinghua.edu.cn/fedora/releases/39/Everything/x86_64/os/repodata/repomd.xml
time wget -O /dev/null https://mirrors.ustc.edu.cn/fedora/releases/39/Everything/x86_64/os/repodata/repomd.xml

比较下载时间,选择最快的源。

系统升级注意事项#

升级 Fedora 版本#

在升级 Fedora 版本前,建议恢复为官方源:

PRTCL // BASH
Terminal window
sudo cp /etc/yum.repos.d.backup/* /etc/yum.repos.d/
sudo dnf clean all
sudo dnf upgrade --refresh

升级完成后再次更换为镜像源。

或直接使用镜像源升级#

PRTCL // BASH
Terminal window
sudo dnf upgrade --refresh
sudo dnf install dnf-plugin-system-upgrade -y
sudo dnf system-upgrade download --releasever=40
sudo dnf system-upgrade reboot

参考资料#

R P
Rhine Lab Pioneer Division
Auth_Verified: 2026.04.08
// END OF POST

订阅

通过 RSS 订阅本站,新文章发布时第一时间收到通知。

Follow
Classified
Chapter_06
Protocol_Ref: CC-BY-NC-SA-4.0

Fedora换源教程

Author: CHONGXIReleased: 2026.04.08

Licensed under CC BY-NC-SA 4.0

评论

© 2025-2026 EchoSpace
Powered by Astro & echohaoran Non-Collaborative_Entity // Protocol_V.4.21