各 Linux 发行版修改镜像源
更新: 1/6/2025 字数: 0 字 时长: 0 分钟
Linux 系统安装完后软件源一般都是国外服务器,在国内特别慢,这时候就需要更换国内的镜像源。本文介绍如何给 Centos、Ubuntu、Debian、Fedora、OpenSUSE、FreeBSD 系统更换软件源。
Centos
备份
bashmv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
更换源
下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
bashwget -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 生成缓存
bashyum makecache
Ubuntu
备份
bashcp /etc/apt/sources.list /etc/apt/sources.list.bak
更换源
bash# 使用 nano 打开文本 nano /etc/apt/sources.list
删除原来文件里的内容,将下面其中一个源复制进去,然后保存。
清华源:
textdeb 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
阿里源:
textdeb 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
更新
bashapt update
修复损坏的软件包,尝试卸载出错的包,重新安装正确版本的。
bashapt -f install
更新软件
bashapt upgrade
Debian
备份
bash# 将以前的源备份一下,以防以后可以用的 cp /etc/apt/sources.list /etc/apt/sources.list.bak
更换源
使用 nano 编辑 /etc/apt/sources.list 文件
bashnano /etc/apt/sources.list
加入如下内容:
textdeb 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
更新
bashapt update
修复损坏的软件包,尝试卸载出错的包,重新安装正确版本的。
bashapt -f install
更新软件
bashapt upgrade
OpenSUSE
禁用原有软件源
bashsudo zypper mr -da
添加科大镜像源
bashsudo 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
手动刷新软件源
bashsudo zypper ref
更新系统
bashsudo zypper up
FreeBSD
修改 pkg 源
bashmkdir -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 源
bashvim /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 源
bashvim /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/ (推荐)
贡献者
wkwbk