各 Linux 发行版修改镜像源
LI SIR Lv4
本文距离上次更新已过去 0 天,部分内容可能已经过时,请注意甄别。

Linux 系统安装完后软件源一般都是国外服务器,在国内特别慢,这时候就需要更换国内的镜像源。本文介绍如何给 Centos、Ubuntu、Debian、Fedora、OpenSUSE、FreeBSD 系统更换软件源。


Centos

  1. 备份

    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/

    1
    2
    3
    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 生成缓存

    1
    yum makecache

Ubuntu

  1. 备份

    1
    cp /etc/apt/sources.list /etc/apt/sources.list.bak
  2. 更换源

    1
    2
    # 使用 nano 打开文本
    nano /etc/apt/sources.list

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

    清华源:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    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
  3. 更新

    1
    apt update

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

    1
    apt -f install

    更新软件

    1
    apt upgrade

Debian

  1. 备份

    1
    2
    # 将以前的源备份一下,以防以后可以用的
    cp /etc/apt/sources.list /etc/apt/sources.list.bak
  2. 更换源

    使用 nano 编辑 /etc/apt/sources.list 文件

    1
    nano /etc/apt/sources.list

    加入如下内容:

    1
    2
    3
    4
    5
    6
    7
    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
  3. 更新

    1
    apt update

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

    1
    apt -f install

    更新软件

    1
    apt upgrade

OpenSUSE

  1. 禁用原有软件源

    1
    sudo zypper mr -da
  2. 添加科大镜像源

    1
    2
    3
    4
    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. 手动刷新软件源

    1
    sudo zypper ref
  4. 更新系统

    1
    sudo zypper up

FreeBSD

  1. 修改 pkg 源

    1
    2
    3
    4
    5
    6
    7
    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 源

    1
    2
    3
    4
    5
    6
    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 源

    1
    2
    3
    4
    vim /etc/portsnap.conf

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

国内开源镜像站

大学类

公司类

PyPi 镜像

 评论
评论插件加载失败
正在加载评论插件
总字数 116.8k 访客数 访问量