首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux系统各发行版换国内yum或apt源,加速软件下载更新

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

作者头像
zeruns
发布2020-04-07 10:49:23
2.9K1
发布2020-04-07 10:49:23
举报
文章被收录于专栏:Zeruns的博客Zeruns的博客

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
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-03-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Zeruns 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Centos
    • 1、备份
      • 2、更换源
        • 3、运行yum makecache生成缓存
        • Ubuntu
          • 1.备份
            • 2.更改文件权限使其可编辑
              • 3.更换源
                • 3.更新
                • Debian
                  • 1.备份
                    • 2.更换源
                      • 3.更新
                      • Fedora
                      • OpenSUSE
                        • 1.禁用原有软件源
                          • 2.添加科大镜像源
                            • 3.手动刷新软件源
                              • 4.更新系统
                              • FreeBSD
                                • 1.修改 pkg 源
                                  • 2.修改 ports 源
                                    • 3.修改 portsnap 源
                                    领券
                                    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档