Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

apt update refuses the MongoDB repository because of a GPG signature error

ErrorW: 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 4B7C549A058F8B6B

Short 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.

  • Applies to MongoDB 9.0 Community, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.list
  2. 2Match what you see, then jump to its fix

    1. 1NO_PUBKEY 4B7C549A058F8B6B and 'The repository ... is not signed' right after sudo apt updateThe MongoDB public key was never importedFix
    2. 2gpg: no valid OpenPGP data found.The key import itself failedFix

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 4B7C549A058F8B6B
  • E: 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.gpg

2Fix

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 update

3Verify

apt update finishes with no GPG error for repo.mongodb.org.

sudo apt-get update 2>&1 | grep -i -E 'mongodb|GPG' || echo clean

Confirmed by mongodb.com

Did this fix it?

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 2

2Fix

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 \
   --dearmor

3Verify

The key file now exists and apt update is clean.

ls -l /usr/share/keyrings/mongodb-server-9.gpg
sudo apt-get update

Confirmed by mongodb.com

Did this fix it?

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

Servers

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.