更新ubuntu软件源遇到GPG error
BUG背景
执行sudo apt update
后遇到类似下列报错:
E: The repository 'https://download.docker.com/linux/ubuntu bionic Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease: Unknown error executing apt-key
E: The repository 'http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease: Unknown error executing apt-key
E: The repository 'http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease: Unknown error executing apt-key
原因
一般来说,ubuntu22.04软件源读取/etc/apt/sources.list中的地址。但这个bug的原因是:使用的是/etc/apt/sources.list.d目录下的源地址,正常22.04不应该,24.04优先级才调整到这个目录下。
解决方案
在/etc/apt/sources.list.d下新建ubuntu.list,内容:
# 针对ubuntu22.04版本的,其他版本需要修改
deb [signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg] http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
deb [signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg] http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
deb [signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg] http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
deb [signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg] http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
将/etc/apt/sources.list内容修改为空。