Ubuntu18.04安装MongoDB4.4后执行apt-get update出现GPG错误
解决Ubuntu 18.04上MongoDB 4.4的apt update GPG错误(关联MongoDB 4.0仓库)
问题说明
在Ubuntu 18.04安装MongoDB 4.4后,执行sudo apt-get update时出现MongoDB 4.0仓库的GPG密钥过期错误,即使仅安装了4.4版本,原因是系统中残留了MongoDB 4.0的仓库配置文件。
错误日志如下:
Ign:2 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 InRelease Ign:3 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 InRelease Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease Hit:5 http://us.archive.ubuntu.com/ubuntu bionic InRelease Get:6 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 Release [2,989 B] Hit:7 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease Hit:8 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 Release Hit:10 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease Get:11 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 Release.gpg [801 B] Ign:11 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 Release.gpg Reading package lists... Done W: GPG error: https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 Release: The following signatures were invalid: EXPKEYSIG 68818C72E52529D4 MongoDB 4.0 Release Signing Key <packaging@mongodb.com> E: The repository 'https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 Release' 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.
解决步骤
列出系统中所有MongoDB相关的仓库配置文件:
ls /etc/apt/sources.list.d/mongodb*.list你会看到包含
mongodb-org-4.0.list的文件,这就是问题根源。删除MongoDB 4.0的仓库配置文件:
sudo rm /etc/apt/sources.list.d/mongodb-org-4.0.list若不确定文件名,可先查看文件内容确认:
cat /etc/apt/sources.list.d/mongodb-org-4.0.list重新导入MongoDB 4.4的官方GPG密钥(确保密钥有效):
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -执行更新命令验证问题是否解决:
sudo apt-get update
内容的提问来源于stack exchange,提问作者Joseph_01
相关产品推荐
相关产品推荐

