636 字
3 分钟
Linux换源和CentOS切换备用源
前言
众所周知 CentOS 7
系统已于2024年06月30日停止维护,并且再也没有新版本会维护了,所以我建议大佬们能迁移还是尽量迁移,推荐迁移到Ubuntu
或者Debian
系统,我自己比较喜欢Debian
系统,因为轻量也稳定。新手小白我推荐使用Ubuntu
系统,因为预装了很多工具和库。虽然CentOS
系统全都停止维护了,但是还是可以使用的,只是yum源失效了,所以本文介绍换源的操作。
使用开源的换源脚本,支持多种Linux系统换源。
国内环境:
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)
海外环境切换官方源:
bash <(curl -sSL https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh) --use-official-source true
此脚本会自动识别你的Linux
版本,CentOS
系统切换官方源时会自动使用备用源。推荐使用!
可选项:手动换源教程
这里只列出了我常用的系统,其他系统请网上搜索一下对应的源替换一下就行了,步骤都是一样的,然后换源是需要root权限的。
建议先备份sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
然后打开文件/etc/apt/sources.list
替换源
国内清华大学debian 11
源
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-security bullseye-security main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security 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
国内清华大学ubuntu 20.04
源
deb 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 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
## Pre-released source, not recommended.
# 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
官方debian 11
源
deb https://deb.debian.org/debian/ bullseye main contrib non-free
deb-src https://deb.debian.org/debian/ bullseye main contrib non-free
deb https://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb-src https://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb https://deb.debian.org/debian/ bullseye-backports main contrib non-free
deb-src https://deb.debian.org/debian/ bullseye-backports main contrib non-free
deb https://deb.debian.org/debian-security/ bullseye-security main contrib non-free
deb-src https://deb.debian.org/debian-security/ bullseye-security main contrib non-free
官方debian 12
源
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
然后更新源就可以了
sudo apt update
CentOS 7.9
切换官方备用vault源
创建和修改/etc/yum.repos.d/CentOS-Base.repo
文件
[base]
name=CentOS-$releasever - Base
baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras
baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
清理缓存并生成新的缓存
sudo yum clean all
sudo yum makecache
运行 yum repolist
命令,确保新源已生效
sudo yum repolist
CentOS 7
切换阿里源
下载源到指定目录
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
清理缓存并生成新的缓存
sudo yum clean all
sudo yum makecache
运行 yum repolist
命令,确保新源已生效
sudo yum repolist