Getting error while updating MongoDB from 6 to 7 in Ubuntu 22.04

I have been following the instructions to upgrade the MongoDB server from 6 to 7 from the official page. Then I tried to install version 7 according to this. When I run sudo apt-get update, I am getting the following error:

Hit:1 jammy InRelease
Hit:2 jammy-updates InRelease
Hit:3 jammy-backports InRelease
Hit:4 focal InRelease
Ign:5 jammy/mongodb-org/7.0 InRelease
Hit:6 jammy-security InRelease
Get:7 jammy/mongodb-org/7.0 Release [2090 B]
Get:8 jammy/mongodb-org/7.0 Release.gpg [866 B]
Ign:8 jammy/mongodb-org/7.0 Release.gpg
Reading package lists... Done
W: GPG error: jammy/mongodb-org/7.0 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 160D26BB1785BA38
E: The repository ' jammy/mongodb-org/7.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.

My keyring is in place in this file: /usr/share/keyrings/mongodb-server-7.0.gpg

How to fix this error?

1 Like

Same issue.

The docs say to just repeat the Import the public key used by the package management system step, but that didn’t work for me.

1 Like

One thing I found was the keyring is not showing when running sudo apt-key list. No matter how many times I run the curl -fsSL | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor command, the key ring doesn’t show up there but the file is created.

I found that the keyring is not showing when running sudo apt-key list for me.

1 Like

The solution is to put the keyring location in the sources file.

Edit the file using sudo vi /etc/apt/sources.list.d/mongodb-org-7.0.list and put this instead:

deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] jammy/mongodb-org/7.0 multiverse

Reference to how key rings work: repository - What commands (exactly) should replace the deprecated apt-key? - Ask Ubuntu

1 Like

Another solution is to create the keyring in /etc/apt/trusted.gpg.d/ instead of /usr/share/keyrings/.
The command would be

curl -fsSL | \
   sudo gpg -o /etc/apt/trusted.gpg.d/mongodb-server-7.0.gpg \

Then sudo apt-get update to check if it can find the keyring

1 Like

Thanks, it works bullseye/mongodb-org/7.0 Release.gpg [866 B]

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.