Centos7、Ubuntu系统换源
清华大学开源软件镜像站
https://mirrors.tuna.tsinghua.edu.cn/
直通车:清华大学开源软件镜像站
Centos7
所使用的 Linux 版本为 Centos7.6
手动换源
将原来源备份(选)
cp /etc/apt/source.list /etc/apt/source.list.bak
1、换源
vi /etc/yum.repos.d/CentOS-Base.repo
替换为
[base]
name=CentOS-7- Base
baseurl=https://mirrors6.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/os/x86_64/
enabled=1
gpgcheck=0
Esc+wq 退出
2、更新源
sudo yum clean all
sudo yum makecache
sudo yum -y update
使用bash脚本换源
创建脚本:
vi changesource.sh
#!/bin/bash
echo "正在更换yum源..."
# 使用 bash -c 来写入新的 yum 源配置
sudo bash -c 'cat > /etc/yum.repos.d/CentOS-Base.repo' << EOF
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/os/x86_64/
gpgcheck=0
enabled=1
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/updates/x86_64/
gpgcheck=0
enabled=1
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/extras/x86_64/
gpgcheck=0
enabled=1
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/centosplus/x86_64/
gpgcheck=0
enabled=1
EOF
echo "yum源已更换为清华源"
sudo yum clean all
echo "已清除缓存"
echo "正在更新缓存..."
sudo yum makecache
echo "正在更新软件包..."
sudo yum -y update
echo "完成!"
给bash文件赋予执行权限,并运行
chmod +x changesource.sh
./changesource.sh
一键完成换源
sudo bash -c 'cat > /etc/yum.repos.d/CentOS-Base.repo' << EOF
[base]
name=CentOS-7- Base
baseurl=https://mirrors6.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/os/x86_64/
enabled=1
gpgcheck=0
EOF
sudo yum clean all
sudo yum makecache
sudo yum -y update
Ubuntu
所使用的 Linux 版本为 Ubuntu 22.04
手动换源
将原来源备份(选)
cp /etc/apt/source.list /etc/apt/source.list.bak
1、换源
常用的Ubuntu版本代号如下:
Ubuntu 22.04:jammy
Ubuntu 20.04:focal
Ubuntu 18.04:bionic
Ubuntu 16.04:xenia
vi /etc/apt/source.list
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
Esc+wq 退出
2、更新源
sudo apt-get -y update
sudo apt-get -y upgrade
使用bash脚本换源
创建脚本:
vi changesource.sh
#!/bin/bash
# 备份当前的 sources.list 文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 更新 sources.list 文件
sudo bash -c 'cat > /etc/apt/sources.list' << EOF
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
EOF
# 更新软件包列表
sudo apt-get -y update
# 升级已安装的软件包
sudo apt-get -y upgrade
给bash文件赋予执行权限,并运行
chmod +x changesource.sh
./changesource.sh
一键完成换源
sudo bash -c 'cat > /etc/apt/sources.list' << EOF
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
EOF
sudo apt-get -y update
sudo apt-get -y upgrade
标签:list,edu,系统,apt,etc,换源,Linux,bash
From: https://blog.csdn.net/2303_76330735/article/details/143312827