换源手册

换源手册

提示
本文完全基于个人使用整理,主要使用南京大学镜像源。以下是常用镜像站的帮助手册,您可以根据需要选择:

Linux换源

Ubuntu换源 🔖参考

sources.list 格式 (Ubuntu 22.04 及更早版本)

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's@//.*archive.ubuntu.com@//mirror.nju.edu.cn@g' /etc/apt/sources.list

DEB822 格式

sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak
sudo sed -i 's@//.*archive.ubuntu.com@//mirror.nju.edu.cn@g' /etc/apt/sources.list.d/ubuntu.sources

24.04 LTS专用

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
cat <<'EOF' > /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirror.nju.edu.cn/ubuntu/ noble main restricted universe multiverse
# deb-src https://mirror.nju.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirror.nju.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
# deb-src https://mirror.nju.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirror.nju.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# deb-src https://mirror.nju.edu.cn/ubuntu/ noble-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
# deb https://mirror.nju.edu.cn/ubuntu/ noble-security main restricted universe multiverse
# # deb-src https://mirror.nju.edu.cn/ubuntu/ noble-security main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirror.nju.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
# # deb-src https://mirror.nju.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
EOF

Python

Pypi换源 🔖参考

临时使用

pip install -i https://mirror.nju.edu.cn/pypi/web/simple some-package

更新并换源

python -m pip install -i https://mirror.nju.edu.cn/pypi/web/simple --upgrade pip
pip config set global.index-url https://mirror.nju.edu.cn/pypi/web/simple

Anaconda换源 🔖参考

默认配置保存在用户目录下的 .condarc 文件,若不存在,建议使用命令生成文件

conda config --set show_channel_urls yes
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirror.nju.edu.cn/anaconda/pkgs/main
  - https://mirror.nju.edu.cn/anaconda/pkgs/r
  - https://mirror.nju.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirror.nju.edu.cn/anaconda/cloud
  pytorch: https://mirror.nju.edu.cn/anaconda/cloud

换源手册
http://blog.zhens.site/program-source/
作者
zhens
发布于
2025年6月22日
许可协议