apt update refuses the MongoDB repository because of a GPG signature error
W: GPG error: https://repo.mongodb.org/apt/ubuntu <release>/mongodb-org/9.0 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4B7C549A058F8B6BShort answer
apt rejects the MongoDB repository when it has no copy of MongoDB's public key. Either the key was never imported, or the import failed and left an empty file. Install gnupg and curl, run the key import command from MongoDB's install guide exactly as written, then run apt update again.
Fix it fast
1Find out which cause you have
Check whether the key file the repository entry points to exists and has content, and see what the list file says.
ls -l /usr/share/keyrings/mongodb-server-9.gpg cat /etc/apt/sources.list.d/mongodb-org-9.0.list2Match what you see, then jump to its fix
What does the error look like?
W: GPG error: https://repo.mongodb.org/apt/ubuntu <release>/mongodb-org/9.0 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4B7C549A058F8B6BE: The repository 'https://repo.mongodb.org/apt/ubuntu <release>/mongodb-org/9.0 Release' is not signed.gpg: no valid OpenPGP data found.
Cause 1 of 2
The MongoDB public key was never imported
1Check
The key file is missing, or you added the repository line without running the key step. MongoDB's guide says this error usually comes from a missing public GPG key.
ls -l /usr/share/keyrings/mongodb-server-9.gpg2Fix
Run the key import from the install guide again, exactly as printed there, then update.
sudo apt-get install gnupg curl
curl -fsSL https://pgp.mongodb.com/server-9.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-9.gpg \
--dearmor
sudo apt-get update3Verify
apt update finishes with no GPG error for repo.mongodb.org.
sudo apt-get update 2>&1 | grep -i -E 'mongodb|GPG' || echo cleanConfirmed by mongodb.com
Cause 2 of 2
The key import itself failed
1Check
The install guide treats this as a copy problem: the import command was retyped or cut, so gpg received something that is not a key. gnupg and curl must also be installed, as the guide's first step says.
which gpg curl
curl -fsSL https://pgp.mongodb.com/server-9.asc | head -n 22Fix
Delete the broken key file, install the two tools, and paste the import command from the guide without changes.
sudo rm -f /usr/share/keyrings/mongodb-server-9.gpg
sudo apt-get install gnupg curl
curl -fsSL https://pgp.mongodb.com/server-9.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-9.gpg \
--dearmor3Verify
The key file now exists and apt update is clean.
ls -l /usr/share/keyrings/mongodb-server-9.gpg
sudo apt-get updateConfirmed by mongodb.com
How do I stop it coming back?
- Copy the key and list-file commands from MongoDB's install guide for your Ubuntu release instead of retyping them.
- Keep the list file name and key file name from the guide so the two stay paired.
- After any change to the repository, run sudo apt-get update and read its output before installing.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Databases
systemctl cannot find mongod.service on Ubuntu
Unable to locate package mongodb-org
The mongod.service unit comes from MongoDB's own mongodb-org package.
2 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix