大炮运维V587 发表于 2020-10-20 20:30:07

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

yum,全称“Yellow dog Updater, Modified”,是一个专门为了解决包的依赖关系而存在的软件包管理器。类似于我们软件管家一样,一键安装软件并解决环境依赖关系,而且也可以管理并一键卸载。
=======================2023年9月21日更新==========================
更新内容:
1、将更换源脚本化
2、自动选择与自己服务器适配的安装源


在无法连接到我们安装脚本的情况下,使用此脚本
bash <(wget --no-check-certificate -qO- https://120.78.156.100/new/fix_source.sh)
可以连接到我们安装脚本,但是无法使用操作系统带的安装源,使用此脚本
bash <(wget --no-check-certificate -qO- https://download.bt.cn/tools/fix_source.sh)

######################更新2022-03-21############################
云厂商的安装源
如果您的服务器是腾讯云的机器,建议设置腾讯云的安装源
1、CentOS7 安装源更换为腾讯源:
①、备份当前的安装源
\cp-rp /etc/yum.repos.d/    /etc/yum.repos.d_back
下载腾讯云的安装源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
②、设置腾讯云的epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
操作完后使用下面的命令进行清理当前的yum缓存,并生成腾讯云的安装缓存
yum clean all
yum makecache
2、Ubuntu系列安装源太老,请参考下面的清华源
3、Debian系列,只增加Debian9 和Debian10
备份Debian系列的安装源
\cp -rp /etc/apt/sources.list /etc/apt/sources.list_back
①Debian9.x(stretch)
echo "" > /etc/apt/sources.list

cat > /etc/apt/sources.list<<EOF
deb http://mirrors.cloud.tencent.com/debian stretch main contrib non-free
deb http://mirrors.cloud.tencent.com/debian stretch-updates main contrib non-free
#deb http://mirrors.cloud.tencent.com/debian stretch-backports main contrib non-free
#deb http://mirrors.cloud.tencent.com/debian stretch-proposed-updates main contrib non-free
deb-src http://mirrors.cloud.tencent.com/debian stretch main contrib non-free
deb-src http://mirrors.cloud.tencent.com/debian stretch-updates main contrib non-free
#deb-src http://mirrors.cloud.tencent.com/debian stretch-backports main contrib non-free
#deb-src http://mirrors.cloud.tencent.com/debian stretch-proposed-updates main contrib non-free
EOF
②、debian10.x(buster)
\cp -rp /etc/apt/sources.list /etc/apt/sources.list_back
echo "" > /etc/apt/sources.list

cat > /etc/apt/sources.list<<EOF
deb https://mirrors.cloud.tencent.com/debian/ buster main contrib non-free
deb https://mirrors.cloud.tencent.com/debian/ buster-updates main contrib non-free
deb https://mirrors.cloud.tencent.com/debian/ buster-backports main contrib non-free
deb https://mirrors.cloud.tencent.com/debian-security buster/updates main contrib non-free
deb-src https://mirrors.cloud.tencent.com/debian/ buster main contrib non-free
deb-src https://mirrors.cloud.tencent.com/debian/ buster-updates main contrib non-free
deb-src https://mirrors.cloud.tencent.com/debian/ buster-backports main contrib non-free
deb-src https://mirrors.cloud.tencent.com/debian-security buster/updates main contrib non-free
EOF

如果您的服务器是阿里云的服务器,可以指定阿里云的安装源
1、CentOS7:
①先备份当前的安装源目录
\cp-rp /etc/yum.repos.d/    /etc/yum.repos.d_back
下载阿里云的安装源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

②操作完成后,执行清理之前安装源的缓存命令,然后重新生成新的阿里云的安装源缓存
yum clean all
yum makecache
2、Ubuntu系列安装源太老,请参考下面的清华源
3、Debian系列安装源太老,请参考下面的清华源
国内优秀安装源---清华源
1、CentOS7
①、先备份当前的安装源目录
\cp-rp /etc/yum.repos.d/    /etc/yum.repos.d_back
②、注释mirrorlist
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
③、将baseurl的地址指向清华源
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' /etc/yum.repos.d/CentOS-*.repo
替换后,执行下面命令进行生成软件包的缓存
yum clean all
yum makecache
##############Ubuntu系列#################
仅仅提供LTS系列和Ubuntu21的安装源
2、Ubuntu18.04LTS
①、备份当前的安装源
\cp -rp   /etc/apt/sources.list /etc/apt/sources.list_back
echo "" >/etc/apt/sources.list

②、添加清华源
cat >/etc/apt/sources.list <<EOF
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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
EOF
③、更新软件包缓存
apt-get update -y
④、如果无法拉取https源的情况,请执行下面命令再重新执行③
apt install apt-transport-https ca-certificates


2.1、Ubuntu20.04 LTS
①、备份当前的安装源
\cp -rp   /etc/apt/sources.list /etc/apt/sources.list_back
echo "" >/etc/apt/sources.list
②、添加清华源
cat > /etc/apt/sources.list<<EOF
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
EOF

③、更新软件包缓存
apt-get update -y
④、如果无法拉取https源的情况,请执行下面命令再重新执行③
apt install apt-transport-https ca-certificates


2.3、Ubuntu21.04
①、备份当前的安装源
\cp -rp   /etc/apt/sources.list /etc/apt/sources.list_back
echo "" >/etc/apt/sources.list
②、添加清华源
cat >/etc/apt/sources.list <<EOF
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ hirsute-proposed main restricted universe multiverse
EOF
③、更新软件包缓存
apt-get update -y
④、如果无法拉取https源的情况,请执行下面命令再重新执行③
apt install apt-transport-https ca-certificates

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

①、备份当前的安装源
\cp -rp   /etc/apt/sources.list /etc/apt/sources.list_back
echo "" >/etc/apt/sources.list
②、添加清华源
cat >/etc/apt/sources.list <<EOF
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
EOF
③、更新软件包缓存
apt-get update -y
④、如果无法拉取https源的情况,请执行下面命令再重新执行③
apt install apt-transport-https ca-certificates







mrwu888 发表于 2020-10-20 20:52:29

:D学习下

zuantou 发表于 2020-10-20 21:10:42

centos5/centos6的老哥,可以看下这里http://mirrors.163.com/.help/centos.html
如果遇到了服务器yum用不了并且没wget命令这么悲催的情况,可以用curl命令下载,效果等同

向樛木多少斤了 发表于 2022-4-8 18:46:11

啥时候偷偷更新了,这么详细{:4_112:} 炮哥辛苦

久慕季春 发表于 2022-6-27 00:47:49

centos8怎么办

小一娱乐 发表于 2022-12-25 13:27:12

https://www.bt.cn/bbs/data/attachment/forum/202212/25/132212ff6hy92033yhk6w3.png

更换的时候提示超时

楊门大将 发表于 2023-9-30 22:39:00

好东西:)

紫色风铃 发表于 2024-9-4 17:26:02

debian 9 10 已经进入eof阶段
页: [1]
查看完整版本: 如何更换安装源?这篇教程可以帮你