各 Linux 发行版修改镜像源
本文距离上次更新已过去 0 天,部分内容可能已经过时,请注意甄别。
Linux 系统安装完后软件源一般都是国外服务器,在国内特别慢,这时候就需要更换国内的镜像源。本文介绍如何给 Centos、Ubuntu、Debian、Fedora、OpenSUSE、FreeBSD 系统更换软件源。
Centos
备份
1
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
更换源
下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
1
2
3wget -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注意:http://mirrors.aliyun.com/repo/Centos-7.repo 中的 7 改为自己的 Centos 版本号,比如 Centos 8 就是 http://mirrors.aliyun.com/repo/Centos-8.repo
然后运行 yum makecache 生成缓存
1
yum makecache
Ubuntu
备份
1
cp /etc/apt/sources.list /etc/apt/sources.list.bak
更换源
1
2# 使用 nano 打开文本
nano /etc/apt/sources.list删除原来文件里的内容,将下面其中一个源复制进去,然后保存。
清华源:
1
2
3
4
5
6
7
8
9
10deb 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
10deb 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
apt update
修复损坏的软件包,尝试卸载出错的包,重新安装正确版本的。
1
apt -f install
更新软件
1
apt upgrade
Debian
备份
1
2# 将以前的源备份一下,以防以后可以用的
cp /etc/apt/sources.list /etc/apt/sources.list.bak更换源
使用 nano 编辑 /etc/apt/sources.list 文件
1
nano /etc/apt/sources.list
加入如下内容:
1
2
3
4
5
6
7deb 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
apt update
修复损坏的软件包,尝试卸载出错的包,重新安装正确版本的。
1
apt -f install
更新软件
1
apt upgrade
OpenSUSE
禁用原有软件源
1
sudo zypper mr -da
添加科大镜像源
1
2
3
4sudo 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
sudo zypper ref
更新系统
1
sudo zypper up
FreeBSD
修改 pkg 源
1
2
3
4
5
6
7mkdir -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",
}修改 ports 源
1
2
3
4
5
6vim /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}/修改 portsnap 源
1
2
3
4vim /etc/portsnap.conf
# content of porsnap.conf
SERVERNAME=porsnap.tw.freebsd.org
国内开源镜像站
大学类
- 清华大学:https://mirrors.tuna.tsinghua.edu.cn/ (推荐)
- 中国科学技术大学:https://mirrors.ustc.edu.cn/ (推荐)
- 浙江大学:http://mirrors.zju.edu.cn/
- 兰州大学:http://mirror.lzu.edu.cn/
- 大连理工大学:http://mirror.dlut.edu.cn/
- 东北大学:http://mirror.neu.edu.cn/
- 大连东软信息学院:http://mirrors.neusoft.edu.cn/
公司类
- 阿里云开源镜像:http://mirrors.aliyun.com/ (推荐)
- 网易开源镜像站:http://mirrors.163.com/
- 搜狐开源镜像站:http://mirrors.sohu.com/
PyPi 镜像
- 豆瓣:https://pypi.doubanio.com/ (推荐)
评论
评论插件加载失败
正在加载评论插件