Ubuntu 22.04安装MongoDB 7时出现「Unable to locate package MongoDB 7」错误的求助
Hey there! I've run into similar headaches setting up MongoDB on Ubuntu before, so let's walk through troubleshooting this step by step:
1. Verify the GPG key was imported correctly
First, check if the MongoDB 7.0 GPG key file actually exists on your system. Run this command:
ls /usr/share/keyrings/mongodb-server-7.0.gpg
If the file doesn't show up, your initial key import might have failed (probably due to line break formatting or network blips). Re-run the import as a single line to avoid issues:
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
2. Double-check your repository list file
Next, confirm the source list entry for MongoDB is 100% accurate. View the file content with:
cat /etc/apt/sources.list.d/mongodb-org-7.0.list
It should exactly match this line:
deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse
If there are typos (like misspelling "jammy" or messing up the repo path), edit the file to fix them. Also, note that MongoDB 7.0 only supports amd64 and arm64 architectures—if you're on a 32-bit system (i386), the package won't exist at all.
3. Check for errors during apt update
When you ran sudo apt-get update, did you see any error messages tied to the MongoDB repository? Common issues include:
NO_PUBKEY: This means the GPG key wasn't imported properly—go back to step 1 to re-import it.- Failed to connect to the repository: This could be a network problem; make sure your server can reach MongoDB's repo server, or try switching networks.
Fix any errors here before attempting to install again.
4. Try installing specific package versions
Sometimes apt can't resolve the latest version automatically. Try installing a specific stable release of MongoDB 7.0 (replace the version number with the latest stable one if needed):
sudo apt-get install -y mongodb-org=7.0.15 mongodb-org-server=7.0.15 mongodb-org-shell=7.0.15 mongodb-org-mongos=7.0.15 mongodb-org-tools=7.0.15
5. Clear apt cache and re-update
Corrupted apt cache can also cause package detection issues. Run these commands to refresh the cache:
sudo apt clean sudo apt update --fix-missing
Then try installing mongodb-org again.
One last check: Make sure Ubuntu's multiverse repository is enabled (your source line specifies it, but it's good to confirm):
sudo add-apt-repository multiverse sudo apt update
Let me know if any of these steps get you up and running!
备注:内容来源于stack exchange,提问作者Infobuscador

