如何更换安装源?这篇教程可以帮你

云厂商的安装源
快速更换源脚本
  1. 在无法连接到我们安装脚本的情况下,使用此脚本
  2. bash <(wget --no-check-certificate -qO- https://120.78.156.100/new/fix_source.sh)
  3. 可以连接到我们安装脚本,但是无法使用操作系统带的安装源,使用此脚本
  4. bash <(wget --no-check-certificate -qO- https://download.bt.cn/tools/fix_source.sh)
如果您的服务器是腾讯云的机器,建议设置腾讯云的安装源

1、CentOS7 安装源更换为腾讯源:
①、备份当前的安装源

  1. \cp  -rp /etc/yum.repos.d/    /etc/yum.repos.d_back

复制代码

下载腾讯云的安装源

  1. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo

复制代码

②、设置腾讯云的epel源

  1. wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo

复制代码

操作完后使用下面的命令进行清理当前的yum缓存,并生成腾讯云的安装缓存

  1. yum clean all
  2. yum makecache

复制代码

2、Ubuntu系列安装源太老,请参考下面的清华源
3、Debian系列,只增加Debian9 和Debian10
备份Debian系列的安装源

  1. \cp -rp /etc/apt/sources.list /etc/apt/sources.list_back

复制代码

①Debian9.x  (stretch)

  1. echo "" > /etc/apt/sources.list

复制代码

  1. cat > /etc/apt/sources.list<<EOF
  2. deb http://mirrors.cloud.tencent.com/debian stretch main contrib non-free
  3. deb http://mirrors.cloud.tencent.com/debian stretch-updates main contrib non-free
  4. #deb http://mirrors.cloud.tencent.com/debian stretch-backports main contrib non-free
  5. #deb http://mirrors.cloud.tencent.com/debian stretch-proposed-updates main contrib non-free
  6. deb-src http://mirrors.cloud.tencent.com/debian stretch main contrib non-free
  7. deb-src http://mirrors.cloud.tencent.com/debian stretch-updates main contrib non-free
  8. #deb-src http://mirrors.cloud.tencent.com/debian stretch-backports main contrib non-free
  9. #deb-src http://mirrors.cloud.tencent.com/debian stretch-proposed-updates main contrib non-free
  10. EOF

复制代码

②、debian10.x(buster)

  1. \cp -rp /etc/apt/sources.list /etc/apt/sources.list_back

复制代码

  1. echo "" > /etc/apt/sources.list

复制代码

  1. cat > /etc/apt/sources.list<<EOF
  2. deb https://mirrors.cloud.tencent.com/debian/ buster main contrib non-free
  3. deb https://mirrors.cloud.tencent.com/debian/ buster-updates main contrib non-free
  4. deb https://mirrors.cloud.tencent.com/debian/ buster-backports main contrib non-free
  5. deb https://mirrors.cloud.tencent.com/debian-security buster/updates main contrib non-free
  6. deb-src https://mirrors.cloud.tencent.com/debian/ buster main contrib non-free
  7. deb-src https://mirrors.cloud.tencent.com/debian/ buster-updates main contrib non-free
  8. deb-src https://mirrors.cloud.tencent.com/debian/ buster-backports main contrib non-free
  9. deb-src https://mirrors.cloud.tencent.com/debian-security buster/updates main contrib non-free
  10. EOF

复制代码

如果您的服务器是阿里云的服务器,可以指定阿里云的安装源

1、CentOS7:
①先备份当前的安装源目录

  1. \cp  -rp /etc/yum.repos.d/    /etc/yum.repos.d_back

复制代码

下载阿里云的安装源

  1. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

复制代码

②操作完成后,执行清理之前安装源的缓存命令,然后重新生成新的阿里云的安装源缓存

  1. yum clean all
  2. yum makecache

复制代码

2、Ubuntu系列安装源太老,请参考下面的清华源
3、Debian系列安装源太老,请参考下面的清华源

国内优秀安装源---清华源

1、CentOS7
①、先备份当前的安装源目录

  1. \cp  -rp /etc/yum.repos.d/    /etc/yum.repos.d_back

复制代码

②、注释mirrorlist

  1. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo

复制代码

③、将baseurl的地址指向清华源

  1. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' /etc/yum.repos.d/CentOS-*.repo

复制代码

替换后,执行下面命令进行生成软件包的缓存

  1. yum clean all
  2. yum makecache

复制代码

##############Ubuntu系列#################

仅仅提供LTS系列和Ubuntu21的安装源
2、Ubuntu18.04LTS
①、备份当前的安装源

  1. \cp -rp   /etc/apt/sources.list /etc/apt/sources.list_back
  2. echo "" >/etc/apt/sources.list

复制代码

②、添加清华源

  1. cat >/etc/apt/sources.list <<EOF
  2. # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
  3. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
  4. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
  5. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
  6. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
  7. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
  8. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
  9. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
  10. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
  11. # 预发布软件源,不建议启用
  12. # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
  13. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
  14. EOF

复制代码

③、更新软件包缓存

  1. apt-get update -y

复制代码

④、如果无法拉取https源的情况,请执行下面命令再重新执行③

  1. apt install apt-transport-https ca-certificates

复制代码

2.1、Ubuntu20.04 LTS
①、备份当前的安装源

  1. \cp -rp   /etc/apt/sources.list /etc/apt/sources.list_back
  2. echo "" >/etc/apt/sources.list

复制代码

②、添加清华源

  1. cat > /etc/apt/sources.list<<EOF
  2. # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
  3. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
  4. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
  5. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
  6. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
  7. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
  8. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
  9. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
  10. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
  11. # 预发布软件源,不建议启用
  12. # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
  13. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
  14. EOF

复制代码

③、更新软件包缓存

  1. apt-get update -y

复制代码

④、如果无法拉取https源的情况,请执行下面命令再重新执行③

  1. apt install apt-transport-https ca-certificates

复制代码

2.3、Ubuntu21.04
①、备份当前的安装源

  1. \cp -rp   /etc/apt/sources.list /etc/apt/sources.list_back
  2. echo "" >/etc/apt/sources.list

复制代码

②、添加清华源

  1. cat >/etc/apt/sources.list <<EOF
  2. # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
  3. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute main restricted universe multiverse
  4. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute main restricted universe multiverse
  5. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-updates main restricted universe multiverse
  6. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-updates main restricted universe multiverse
  7. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-backports main restricted universe multiverse
  8. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-backports main restricted universe multiverse
  9. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-security main restricted universe multiverse
  10. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-security main restricted universe multiverse
  11. # 预发布软件源,不建议启用
  12. # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-proposed main restricted universe multiverse
  13. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-proposed main restricted universe multiverse
  14. EOF

复制代码

③、更新软件包缓存

  1. apt-get update -y

复制代码

④、如果无法拉取https源的情况,请执行下面命令再重新执行③

  1. apt install apt-transport-https ca-certificates

复制代码

############Debian系列##############

debian系列暂时只考虑 bullseye发行版(其他的版本请参考清华源:https://mirrors.tuna.tsinghua.edu.cn/help/debian/

①、备份当前的安装源

  1. \cp -rp   /etc/apt/sources.list /etc/apt/sources.list_back
  2. echo "" >/etc/apt/sources.list

复制代码

②、添加清华源

  1. cat >/etc/apt/sources.list <<EOF
  2. # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
  3. deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
  4. # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
  5. deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
  6. # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
  7. deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
  8. # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
  9. deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
  10. # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
  11. EOF

复制代码

③、更新软件包缓存

  1. apt-get update -y

复制代码

④、如果无法拉取https源的情况,请执行下面命令再重新执行③

  1. apt install apt-transport-https ca-certificates

本本章引用于https://www.bt.cn/bbs/thread-58005-1-1.html

本文由 易云博客 作者:易云 发表,其版权均为 易云博客 所有,文章内容系作者个人观点,不代表 易云博客 对观点赞同或支持。如需转载,请注明文章来源。
22