参考:https://mirrors.cnnic.cn/help/ubuntu/
sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
apt update 报错:
解决方案
先改成 http 协议
sed -i "s@https://@http://@g" /etc/apt/sources.list
apt-get update
更新 ca证书
apt-get install --reinstall ca-certificates
重新改回 https
sed -i "s@http://@https://@g" /etc/apt/sources.list
apt-get update
root@6eaae8478f80:/# sed -i "s@https://@http://@g" /etc/apt/sources.list
root@6eaae8478f80:/# apt-get update
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease [265 kB]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease [114 kB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease [108 kB]
Get:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security InRelease [114 kB]
Get:5 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:6 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:7 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:8 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main amd64 Packages [1275 kB]
Get:9 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/restricted amd64 Packages [1569 kB]
Get:10 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 Packages [2539 kB]
Get:11 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/multiverse amd64 Packages [30.2 kB]
Get:12 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/universe amd64 Packages [1176 kB]
Get:13 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/main amd64 Packages [55.2 kB]
Get:14 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/universe amd64 Packages [27.5 kB]
Get:15 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/restricted amd64 Packages [1461 kB]
Get:16 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/multiverse amd64 Packages [27.5 kB]
Get:17 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/universe amd64 Packages [888 kB]
Get:18 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/main amd64 Packages [2087 kB]
Fetched 23.3 MB in 9s (2576 kB/s)
Reading package lists... Done
root@6eaae8478f80:/# apt-get install --reinstall ca-certificates
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libssl1.1 openssl
The following NEW packages will be installed:
ca-certificates libssl1.1 openssl
0 upgraded, 3 newly installed, 0 to remove and 34 not upgraded.
Need to get 2085 kB of archives.
After this operation, 5796 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 libssl1.1 amd64 1.1.1f-1ubuntu2.16 [1321 kB]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 openssl amd64 1.1.1f-1ubuntu2.16 [621 kB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 ca-certificates all 20211016~20.04.1 [144 kB]
Fetched 2085 kB in 2s (1158 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libssl1.1:amd64.
(Reading database ... 4127 files and directories currently installed.)
Preparing to unpack .../libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb ...
Unpacking libssl1.1:amd64 (1.1.1f-1ubuntu2.16) ...
Selecting previously unselected package openssl.
Preparing to unpack .../openssl_1.1.1f-1ubuntu2.16_amd64.deb ...
Unpacking openssl (1.1.1f-1ubuntu2.16) ...
Selecting previously unselected package ca-certificates.
Preparing to unpack .../ca-certificates_20211016~20.04.1_all.deb ...
Unpacking ca-certificates (20211016~20.04.1) ...
Setting up libssl1.1:amd64 (1.1.1f-1ubuntu2.16) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up openssl (1.1.1f-1ubuntu2.16) ...
Setting up ca-certificates (20211016~20.04.1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Updating certificates in /etc/ssl/certs...
127 added, 0 removed; done.
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for ca-certificates (20211016~20.04.1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
root@6eaae8478f80:/# sed -i "s@http://@https://@g" /etc/apt/sources.list
root@6eaae8478f80:/# apt-get update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease
Hit:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease
Hit:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease
Hit:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security InRelease
Reading package lists... Done