Linux系统各发行版换国内yum或apt源,加速软件下载更新

Centos、Ubuntu、Debian、Fedora、OpenSUSE、FreeBSD系统换软件源

Linux系统安装完后软件源一般都是国外服务器,在国内特别慢,这时候就需要更换国内的镜像源。

高性价比和便宜的VPS/云服务器推荐:https://blog.zeruns.tech/archives/383.html

Centos

1、备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2、更换源

下载新的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

注意http://mirrors.aliyun.com/repo/Centos-7.repo中的7改为自己的Centos版本号,比如Centos 8就是http://mirrors.aliyun.com/repo/Centos-8.repo

3、运行yum makecache生成缓存

yum makecache

Ubuntu

1.备份

sudo cp /etc/apt/sources.list /etc/apt/sources_init.list

将以前的源备份一下,以防以后可以用的。

2.更改文件权限使其可编辑

sudo  chmod  777  /etc/apt/source.list

3.更换源

sudo nano /etc/apt/sources.list

使用nano打开文本,删除原来文件里的内容,将下面其中一个源复制进去,然后保存。

阿里源:

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

清华源:

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

3.更新

更新源

sudo apt-get update

修复损坏的软件包,尝试卸载出错的包,重新安装正确版本的。

sudo apt-get -f install

更新软件

sudo apt-get upgrade

Debian

1.备份

sudo cp /etc/apt/sources.list /etc/apt/sources.list_bak

2.更换源

一般情况下,将/etc/apt/sources.list文件中 Debian 默认的源地址http://deb.debian.org替换为http://mirrors.ustc.edu.cn(清华源)即可。

sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

也可以直接编辑/etc/apt/sources.list文件(v)

sudo vi /etc/apt/sources.list

加入如下内容即可

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

敲击i键进入插入模式,组合键ctrl+shift+v将复制内容粘贴至源文件中,敲击esc键进入命令模式,输入:wq!保存并退出。

其他镜像源:
阿里云:http://mirrors.aliyun.com/
搜狐:http://mirrors.sohu.com/
网易:http://mirrors.163.com/

3.更新

sudo apt-get update

Fedora

su
cd /etc/yum.repos.d/
mv fedora.repo fedora.repo.backup
mv fedora-updates.repo fedora-updates.repo.backup
wget -O /etc/yum.repos.d/fedora.repo http://mirrors.aliyun.com/repo/fedora.repo
wget -O /etc/yum.repos.d/fedora-updates.repo http://mirrors.aliyun.com/repo/fedora-updates.repo
dnf clean all
dnf makecache

OpenSUSE

1.禁用原有软件源

sudo zypper mr -da

2.添加科大镜像源

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

3.手动刷新软件源

sudo zypper ref

4.更新系统

sudo zypper up

FreeBSD

1.修改 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",
}

2.修改 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}/

3.修改 portsnap 源

vim /etc/portsnap.conf

# content of porsnap.conf
SERVERNAME=porsnap.tw.freebsd.org

推荐文章:

搭建内网穿透服务器,带Web面板:https://blog.zeruns.tech/archives/397.html

怎样搭建个人博客:https://blog.zeruns.tech/archives/218.html

CentOS 7安装新内核并启用Google BBR教程:https://blog.zeruns.tech/archives/39.html

vultr $2.5 纯ipv6服务器+CDN搭建同时支持ipv4和ipv6的网站:https://blog.zeruns.tech/archives/345.html

搭建AdGuard Home无广告及跟踪的DNS解析服务器:https://blog.zeruns.tech/archives/318.html

上一篇:DNS设置


下一篇:yum更换国内源、yum下载rpm包、 源码包安装