添加MongoDB 7.0 GPG密钥后无法在apt-key列表中找到且apt update报错的解决方法咨询
Hey there, let's break down your issue and fix it step by step:
First off, the reason you don't see the key in sudo apt-key list is totally expected—modern Debian/Ubuntu systems have moved away from using apt-key to manage repository keys (it's actually deprecated now). Your command correctly added the key to /usr/share/keyrings/mongodb-server-7.0.gpg, which is the new recommended location, but apt-key list only shows keys stored in the old legacy keyrings (like /etc/apt/trusted.gpg or /etc/apt/trusted.gpg.d/).
The real problem here is likely that your MongoDB repository source file isn't configured to use this new keyring, which is why apt update is throwing errors. Here's how to fix it:
Check or create the MongoDB source list file
You need to make sure there's a file in/etc/apt/sources.list.d/that references your new keyring. Let's create it if it doesn't exist:sudo nano /etc/apt/sources.list.d/mongodb-org-7.0.listPaste the following line into the file (replace
jammywith your Ubuntu version codename—likefocalfor 20.04,noblefor 24.04):deb [signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverseSave the file (press
Ctrl+O, thenEnter, thenCtrl+Xto exit nano).Verify the key (optional but helpful)
If you want to confirm the key was added correctly to the new keyring, run this command instead ofapt-key list:gpg --no-default-keyring --keyring /usr/share/keyrings/mongodb-server-7.0.gpg --list-keysYou should see the MongoDB 7.0 signing key listed here.
Run apt update again
Now execute:sudo apt updateThis time, apt should recognize the keyring specified in the source list and verify the repository signatures without errors.
Just to recap: your key import was done the right way (using the new keyring location), the missing piece was linking that keyring to the MongoDB repository in your sources list.
备注:内容来源于stack exchange,提问作者khateeb

