Linux系统中CentOS、Ubuntu和Debian的换源方法与步骤

Spring Lv2

  使用’cat /etc/os-release’查看 linux 发行版本。

Centos 换源

  1. Centos-7.9.2009-aarch64 位操作系统换源;

    参考:https://developer.aliyun.com/mirror/centos-altarch/?spm=a2c6h.13651104.d-2001.10.4508320cZACtYr

  2. Centos-7.9.2009-x86_64​位操作系统换源;

    参考:https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b112ayACT

  清华源参考:https://mirrors.tuna.tsinghua.edu.cn/help/centos/

Ubuntu 换源

  1. 修改 apt 源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd /etc/apt/
cp sources.list sources.list.backup
echo "">sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse" >> sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse" >> sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse" >> sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse" >> sources.list
echo "deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse" >> sources.list
echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse" >> sources.list
echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse" >> sources.list
echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse" >> sources.list
echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse" >> sources.list
echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse" >> sources.list
#更新
apt-get update

更新报错:GPG error:The following signatures couldn‘t be verified because the public

  添加公钥

1
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8

Debian 10 换源

1
2
3
4
5
6
7
8
9
10
11
12
13
cd /etc/apt/
cp sources.list sources.list.backup
echo "">sources.list
echo "deb http://mirrors.163.com/debian/ buster main non-free contrib" >> sources.list
echo "deb http://mirrors.163.com/debian/ buster-updates main non-free contrib" >> sources.list
echo "deb http://mirrors.163.com/debian/ buster-backports main non-free contrib" >> sources.list
echo "deb http://mirrors.163.com/debian-security/ buster/updates main non-free contrib" >> sources.list
echo "deb-src http://mirrors.163.com/debian/ buster main non-free contrib" >> sources.list
echo "deb-src http://mirrors.163.com/debian/ buster-updates main non-free contrib" >> sources.list
echo "deb-src http://mirrors.163.com/debian/ buster-backports main non-free contrib" >> sources.list
echo "deb-src http://mirrors.163.com/debian-security/ buster/updates main non-free contrib" >> sources.list

apt-get update

Debian 11 换源

1
2
3
4
5
6
7
8
9
10
11
12
cd /etc/apt/
cp sources.list sources.list.backup
echo "">sources.list
echo "deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib" >> sources.list
echo "deb https://mirrors.aliyun.com/debian-security/ bullseye-security main" >> sources.list
echo "deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main" >> sources.list
echo "deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib" >> sources.list
echo "deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib" >> sources.list
echo "deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib" >> sources.list
echo "deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib" >> sources.list

apt-get update

Debian 12 换源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

rm -f /etc/apt/sources.list.d/debian.sources

echo "Types: deb" >> /etc/apt/sources.list.d/debian.sources
echo "URIs: https://mirrors.tuna.tsinghua.edu.cn/debian" >> /etc/apt/sources.list.d/debian.sources
echo "Suites: bookworm bookworm-updates bookworm-backports" >> /etc/apt/sources.list.d/debian.sources
echo "Components: main contrib non-free non-free-firmware" >> /etc/apt/sources.list.d/debian.sources
echo "Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg" >> /etc/apt/sources.list.d/debian.sources
echo "" >> /etc/apt/sources.list.d/debian.sources
echo "# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释" >> /etc/apt/sources.list.d/debian.sources
echo "# Types: deb-src" >> /etc/apt/sources.list.d/debian.sources
echo "# URIs: https://mirrors.tuna.tsinghua.edu.cn/debian" >> /etc/apt/sources.list.d/debian.sources
echo "# Suites: bookworm bookworm-updates bookworm-backports" >> /etc/apt/sources.list.d/debian.sources
echo "# Components: main contrib non-free non-free-firmware" >> /etc/apt/sources.list.d/debian.sources
echo "# Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg" >> /etc/apt/sources.list.d/debian.sources
echo "" >> /etc/apt/sources.list.d/debian.sources
echo "# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换" >> /etc/apt/sources.list.d/debian.sources
echo "Types: deb" >> /etc/apt/sources.list.d/debian.sources
echo "URIs: https://security.debian.org/debian-security" >> /etc/apt/sources.list.d/debian.sources
echo "Suites: bookworm-security" >> /etc/apt/sources.list.d/debian.sources
echo "Components: main contrib non-free non-free-firmware" >> /etc/apt/sources.list.d/debian.sources
echo "Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg" >> /etc/apt/sources.list.d/debian.sources
echo "" >> /etc/apt/sources.list.d/debian.sources
echo "# Types: deb-src" >> /etc/apt/sources.list.d/debian.sources
echo "# URIs: https://security.debian.org/debian-security" >> /etc/apt/sources.list.d/debian.sources
echo "# Suites: bookworm-security" >> /etc/apt/sources.list.d/debian.sources
echo "# Components: main contrib non-free non-free-firmware" >> /etc/apt/sources.list.d/debian.sources
echo "# Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg" >> /etc/apt/sources.list.d/debian.sources

apt-get update

  注意: Debian Buster 以上版本默认支持 HTTPS 源。如果遇到无法拉取 HTTPS 源的情况,请先使用 HTTP 源并安装:

1
2
3
4
sed -i 's|https|http|g' /etc/apt/sources.list.d/debian.sources
apt update && apt install -y apt-transport-https ca-certificates
sed -i 's|http|https|g' /etc/apt/sources.list.d/debian.sources
apt update

参考资料

  [1] https://www.jianshu.com/p/9d6b138e366f

  [2] https://blog.csdn.net/qq_35383263/article/details/108549746

  [3] https://mirrors.tuna.tsinghua.edu.cn/help/debian/

  ‍

  • Title: Linux系统中CentOS、Ubuntu和Debian的换源方法与步骤
  • Author: Spring
  • Created at : 2024-05-07 15:59:45
  • Updated at : 2024-12-18 15:55:45
  • Link: https://www.tecacc.com//post/linux-modification-source-14amma.html
  • License: This work is licensed under CC BY-NC-SA 4.0.