如何更换安装Linux源?

Linux

如何更换安装Linux源?

2023-01-13 17:29







yum,全称“Yellow dog Updater, Modified”,是一个专门为了解决包的依赖关系而存在的软件包管理器。类似于我们软件管家一样,一键安装软件并解决环境依赖关系,而且也可以管理并一键卸载。

执行以下脚本,自动根据您的系统进行全自动化操作换YUM

  1. wget http://mirrors.qingyunl.com/Shell/vps/yum_apt_select.sh;bash yum_apt_select.sh

 

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


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. # 预发布软件源,不建议启用
  13. # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
  14. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
  15. 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. # 预发布软件源,不建议启用
  13. # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
  14. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
  15. 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. # 预发布软件源,不建议启用
  13. # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-proposed main restricted universe multiverse
  14. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-proposed main restricted universe multiverse
  15. 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.  
  8. deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
  9. # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
  10.  
  11. deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
  12. # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
  13. EOF


③、更新软件包缓存

  1. apt-get update -y

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

 

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