各种换源指南

清夏晚风

各种换源指南

在使用Linux系统和各种包管理器时,由于网络原因,直接从官方源下载软件包可能会很慢。通过更换为国内镜像源可以显著提高下载速度。本文档汇总了各种常用工具和系统的换源方法。

参考:

PiP换源

永久换源

下列命令将会创建或修改pip的全局配置文件中的index-url字段,将其设置为您提供的URL。这样,当您使用pip安装包时,就会默认从指定的PyPI镜像源下载。

1
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/

常用镜像源列表:

镜像源 URL
阿里云 https://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中科大 http://pypi.mirrors.ustc.edu.cn/simple/

临时换源

如果只需要临时使用某个镜像源,可以使用以下命令:

1
2
pip install 包名 -i 镜像源URL
pip install numpy -i https://mirrors.aliyun.com/pypi/simple/

Linux系统包管理器换源

脚本实现

使用一键换源脚本是最简单的方法,适用于大多数Linux发行版。

官方源:

1
bash <(curl -sSL https://linuxmirrors.cn/main.sh)

Gitee源:

1
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)

GitHub源:

1
bash <(curl -sSL https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh)

手动配置实现

Ubuntu

Ubuntu 20.04
1
2
3
4
5
6
7
8
9
10
11
12
echo "# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirror.bjtu.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirror.bjtu.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirror.bjtu.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirror.bjtu.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirror.bjtu.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirror.bjtu.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirror.bjtu.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirror.bjtu.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirror.bjtu.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirror.bjtu.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse" >/etc/apt/sources.list

CentOS

CentOS 7
1
2
3
4
yum -y install curl && \
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo && \
yum clean all && \
yum makecache
CentOS 8
1
2
3
4
yum -y install curl && \
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos8_base.repo && \
yum clean all && \
yum makecache

Alpine

1
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

Debian

Debian 12
1
2
3
4
5
6
7
8
echo 'deb https://mirrors.aliyun.com/debian/ bookworm main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib' > /etc/apt/sources.list
Debian 11
1
2
3
4
5
6
7
8
9
10
echo "
deb http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src http://mirrors.aliyun.com/debian-security/ bullseye-security main
deb http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
" >/etc/apt/sources.list

Docker 换源

脚本实现

使用一键换源脚本是最简单的方法:

1
bash <(curl -sSL https://linuxmirrors.cn/docker.sh)

命令实现

手动配置Docker镜像加速器:

1
2
3
echo '{"registry-mirrors":["https://docker.mirrors.ustc.edu.cn/"]}' > /etc/docker/daemon.json && \
sudo systemctl daemon-reload && \
sudo systemctl restart docker

Docker 镜像仓库代理

对于常用的国外镜像仓库,可以通过以下代理地址加速访问:

GitHub Container Registry (ghcr.io)

ghcr.io 替换为 ghcr.nju.edu.cn 即可。

示例:

1
2
3
4
5
# 原始命令
docker pull ghcr.io/github/super-linter:latest

# 替换后命令
docker pull ghcr.nju.edu.cn/github/super-linter:latest

Quay.io

quay.io 替换为 quay.nju.edu.cn 即可。

示例:

1
2
3
4
5
# 原始命令
docker pull quay.io/prometheus/prometheus:latest

# 替换后命令
docker pull quay.nju.edu.cn/prometheus/prometheus:latest

NVIDIA Container Registry (nvcr.io)

nvcr.io 替换为 ngc.nju.edu.cn 即可。

示例:

1
2
3
4
5
# 原始命令
docker pull nvcr.io/nvidia/pytorch:21.12-py3

# 替换后命令
docker pull ngc.nju.edu.cn/nvidia/pytorch:21.12-py3

Kubernetes (k8s.gcr.io)

k8s.gcr.io 替换为 gcr.nju.edu.cn/google-containers 即可。

示例:

1
2
3
4
5
# 原始命令
docker pull k8s.gcr.io/kube-proxy:v1.18.6

# 替换后命令
docker pull gcr.nju.edu.cn/google-containers/kube-proxy:v1.18.6

Google Container Registry (gcr.io)

gcr.io 替换为 gcr.nju.edu.cn 即可。

示例:

1
2
3
4
5
# 原始命令
docker pull gcr.io/cadvisor/cadvisor:v0.39.3

# 替换后命令
docker pull gcr.nju.edu.cn/cadvisor/cadvisor:v0.39.3

NPM

配置NPM使用淘宝镜像源:

1
npm set registry http://registry.npmmirror.com

OpenWrt

配置OpenWrt使用阿里云镜像源:

1
sed -i 's_downloads.openwrt.org_mirrors.aliyun.com/openwrt_' /etc/opkg/distfeeds.conf

Jenkins

配置Jenkins使用清华大学镜像源:

1
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
  • Title: 各种换源指南
  • Author: 清夏晚风
  • Created at : 2025-12-20 17:36:39
  • Updated at : 2026-01-13 16:48:23
  • Link: https://blog.kimikkorow.eu.org/计算机基础/操作系统相关/操作系统使用相关/Linux/公共基础/other/换源/各种换源指南/
  • License: This work is licensed under CC BY-NC-SA 4.0.