Linux 软件源加速

发行版软件源加速

Debian、Ubuntu、CentOS、Rocky、AlmaLinux、Fedora、Arch、Alpine、openSUSE 的软件源,都可以换成本站地址。

● 一键换源脚本 ● 支持 --dry-run 预览 ● 支持 --restore 还原
加速入口

加速入口

点一下即可切换页面上的加速地址;延迟会按你的网络自动重测,带「推荐」的是对你最快的入口,页面示例默认就用它 查看详情 →

一键换源脚本

建议先 dry-run

脚本由官网统一保存,切换加速入口时会自动补上参数。自动识别 Debian / Ubuntu 与发行版代号,同时支持传统的 sources.list 与 deb822 的 *.sources。第三方源(PPA、Docker 源等)不会被改动。

先预览改动
curl -fsSL "https://www.gh-proxy.cn/scripts/apt.sh" | sh -s -- --dry-run

确认后执行

换源并更新
curl -fsSL "https://www.gh-proxy.cn/scripts/apt.sh" | sudo sh                # 换源并 apt update
curl -fsSL "https://www.gh-proxy.cn/scripts/apt.sh" | sudo sh -s -- --no-update  # 只换源
curl -fsSL "https://www.gh-proxy.cn/scripts/apt.sh" | sudo sh -s -- --restore    # 还原

停用无法经过镜像的 mirrorlist / metalink,启用并改写 baseurl;订阅源 redhat.repo 保持原样。

先预览改动
curl -fsSL "https://www.gh-proxy.cn/scripts/dnf.sh" | sh -s -- --dry-run

确认后执行

换源并刷新缓存
curl -fsSL "https://www.gh-proxy.cn/scripts/dnf.sh" | sudo sh
curl -fsSL "https://www.gh-proxy.cn/scripts/dnf.sh" | sudo sh -s -- --no-update
curl -fsSL "https://www.gh-proxy.cn/scripts/dnf.sh" | sudo sh -s -- --restore

重写 /etc/pacman.d/mirrorlist。换源后请用 pacman -Syu 完整升级,避免部分升级。

先预览改动
curl -fsSL "https://www.gh-proxy.cn/scripts/pacman.sh" | sh -s -- --dry-run
确认后执行
curl -fsSL "https://www.gh-proxy.cn/scripts/pacman.sh" | sudo sh
curl -fsSL "https://www.gh-proxy.cn/scripts/pacman.sh" | sudo sh -s -- --restore

按 /etc/alpine-release 自动识别分支(也可用 --branch v3.20 指定)。

先预览改动
curl -fsSL "https://www.gh-proxy.cn/scripts/apk.sh" | sh -s -- --dry-run
确认后执行
curl -fsSL "https://www.gh-proxy.cn/scripts/apk.sh" | sudo sh
curl -fsSL "https://www.gh-proxy.cn/scripts/apk.sh" | sudo sh -s -- --restore

改写 /etc/zypp/repos.d/*.repo 里的 baseurl。

先预览改动
curl -fsSL "https://www.gh-proxy.cn/scripts/zypper.sh" | sh -s -- --dry-run
确认后执行
curl -fsSL "https://www.gh-proxy.cn/scripts/zypper.sh" | sudo sh
curl -fsSL "https://www.gh-proxy.cn/scripts/zypper.sh" | sudo sh -s -- --restore

镜像路径对照

发行版上游本站地址
Debiandeb.debian.org/debianhttps://gh-proxy.cn/debian
Debian 安全更新deb.debian.org/debian-securityhttps://gh-proxy.cn/debian-security
Debian portsdeb.debian.org/debian-portshttps://gh-proxy.cn/debian-ports
Ubuntuarchive.ubuntu.com/ubuntuhttps://gh-proxy.cn/ubuntu
Ubuntu 安全更新security.ubuntu.com/ubuntuhttps://gh-proxy.cn/ubuntu-security
Ubuntu portsports.ubuntu.com/ubuntu-portshttps://gh-proxy.cn/ubuntu-ports
CentOS Streammirror.stream.centos.orghttps://gh-proxy.cn/centos-stream
CentOS 归档vault.centos.orghttps://gh-proxy.cn/centos-vault
Fedoradl.fedoraproject.org/pub/fedora/linuxhttps://gh-proxy.cn/fedora
EPELdl.fedoraproject.org/pub/epelhttps://gh-proxy.cn/epel
Rocky Linuxdl.rockylinux.org/pub/rockyhttps://gh-proxy.cn/rockylinux
AlmaLinuxrepo.almalinux.org/almalinuxhttps://gh-proxy.cn/almalinux
Arch Linuxgeo.mirror.pkgbuild.comhttps://gh-proxy.cn/archlinux
Alpine Linuxdl-cdn.alpinelinux.org/alpinehttps://gh-proxy.cn/alpine
openSUSEdownload.opensuse.orghttps://gh-proxy.cn/opensuse

手动配置时,只需把上面「上游」这一列的地址替换成「本站地址」,路径部分保持不变。 软件包签名与校验和仍然由 apt / dnf / pacman / apk / zypper 本地校验,本站不修改任何包内容。

也可以把上游地址整段替换成本站域名(例如 deb https://gh-proxy.cn noble main):/dists/ 会按发行版代号自动识别 Debian 与 Ubuntu,/pool/ 跟随你这次使用过的发行版; Alpine、Arch、CentOS Stream、Fedora、openSUSE 的目录同样能识别。 带发行版目录的写法最明确,建议优先使用。

各加速服务器的换源脚本

共 2 条

脚本由官网统一保存,命令用 ?node= 把加速地址固定到某台服务器上; 脚本会先备份原配置,支持 --dry-run 预览与 --restore 还原。

官网 · https://gh-proxy.cn
curl -fsSL "https://www.gh-proxy.cn/scripts/apt.sh?node=https://gh-proxy.cn" | sh -s -- --dry-run
EdgeOne 加速 · https://eo.gh-proxy.cn
curl -fsSL "https://www.gh-proxy.cn/scripts/apt.sh?node=https://eo.gh-proxy.cn" | sh -s -- --dry-run

手动示例 · Debian 12

/etc/apt/sources.list
deb https://gh-proxy.cn/debian bookworm main contrib non-free non-free-firmware
deb https://gh-proxy.cn/debian bookworm-updates main contrib non-free non-free-firmware
deb https://gh-proxy.cn/debian-security bookworm-security main contrib non-free non-free-firmware

手动示例 · Rocky 9

/etc/yum.repos.d/rocky.repo
[baseos]
name=Rocky Linux $releasever - BaseOS
baseurl=https://gh-proxy.cn/rockylinux/$releasever/BaseOS/$basearch/os/
enabled=1
gpgcheck=1

使用前请知悉

脚本只会改写发行版官方源,并在改动前把原文件备份为 *.gha-bak,随时可以还原; 建议先执行 --dry-run 确认改动内容。软件源是系统级配置,请确保你了解自己在做什么, 生产环境建议先在测试机上验证。