各 Linux 发行版修改镜像源
Linux 系统安装完后软件源一般都是国外服务器,在国内特别慢,这时候就需要更换国内的镜像源。本文介绍如何给 Centos、Ubuntu、Debian、Fedora、OpenSUSE、FreeBSD 系统更换软件源。
# Centos
备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
1更换源
下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #或者 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
1
2
3注意:http://mirrors.aliyun.com/repo/Centos-7.repo (opens new window) 中的 7 改为自己的 Centos 版本号,比如 Centos 8 就是 http://mirrors.aliyun.com/repo/Centos-8.repo (opens new window)
然后运行 yum makecache 生成缓存
yum makecache
1
# Ubuntu
备份
cp /etc/apt/sources.list /etc/apt/sources.list.bak
1更换源
# 使用 nano 打开文本 nano /etc/apt/sources.list
1
2删除原来文件里的内容,将下面其中一个源复制进去,然后保存。
清华源:
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
1
2
3
4
5
6
7
8
9
10阿里源:
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
1
2
3
4
5
6
7
8
9
10更新
apt update
1修复损坏的软件包,尝试卸载出错的包,重新安装正确版本的。
apt -f install
1更新软件
apt upgrade
1
# Debian
备份
# 将以前的源备份一下,以防以后可以用的 cp /etc/apt/sources.list /etc/apt/sources.list.bak
1
2更换源
使用 nano 编辑 /etc/apt/sources.list 文件
nano /etc/apt/sources.list
1加入如下内容:
deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free # deb-src http://mirrors.ustc.edu.cn/debian stable main contrib non-free deb http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free # deb-src http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free # deb http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free # deb-src http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free
1
2
3
4
5
6
7更新
apt update
1修复损坏的软件包,尝试卸载出错的包,重新安装正确版本的。
apt -f install
1更新软件
apt upgrade
1
# OpenSUSE
禁用原有软件源
sudo zypper mr -da
1添加科大镜像源
sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/distribution/leap/42.1/repo/oss USTC:42.1:OSS sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/distribution/leap/42.1/repo/non-oss USTC:42.1:NON-OSS sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/update/leap/42.1/oss USTC:42.1:UPDATE-OSS sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/update/leap/42.1/non-oss USTC:42.1:UPDATE-NON-OSS
1
2
3
4手动刷新软件源
sudo zypper ref
1更新系统
sudo zypper up
1
# FreeBSD
修改 pkg 源
mkdir -p /usr/local/etc/pkg/repos vim /usr/local/etc/pkg/repos/FreeBSD.conf # content of FreeBSD.conf FreeBSD: { url: "pkg+http://mirrors.ustc.edu.cn/freebsd-pkg/${ABI}/quarterly", }
1
2
3
4
5
6
7修改 ports 源
vim /etc/make.conf # content of make.conf FETCH_CMD=axel -n 10 -a DISABLE_SIZE=yes MASTER_SITE_OVERRIDE?=http://mirrors.ustc.edu.cn/freebsd-ports/distfiles/${DIST_SUBDIR}/
1
2
3
4
5
6修改 portsnap 源
vim /etc/portsnap.conf # content of porsnap.conf SERVERNAME=porsnap.tw.freebsd.org
1
2
3
4
# 国内开源镜像站
# 大学类
- 清华大学:https://mirrors.tuna.tsinghua.edu.cn/ (opens new window) (推荐)
- 中国科学技术大学:https://mirrors.ustc.edu.cn/ (opens new window) (推荐)
- 浙江大学:http://mirrors.zju.edu.cn/ (opens new window)
- 兰州大学:http://mirror.lzu.edu.cn/ (opens new window)
- 大连理工大学:http://mirror.dlut.edu.cn/ (opens new window)
- 东北大学:http://mirror.neu.edu.cn/ (opens new window)
- 大连东软信息学院:http://mirrors.neusoft.edu.cn/ (opens new window)
# 公司类
- 阿里云开源镜像:http://mirrors.aliyun.com/ (opens new window) (推荐)
- 网易开源镜像站:http://mirrors.163.com/ (opens new window)
- 搜狐开源镜像站:http://mirrors.sohu.com/ (opens new window)
# PyPi 镜像
上次更新: 2024/10/14, 19:46:59