MongoDB is a document-oriented NoSQL database used for modern apps, analytics, and microservices. On Ubuntu you install the official mongodb-org packages from MongoDB Inc.—not the outdated mongodb package from Ubuntu universe, which conflicts with the official repo (MongoDB docs).
This guide shows how to install MongoDB Community Edition on Ubuntu (8.0 tested), import the GPG key the modern way (no deprecated apt-key), pick the correct jammy / noble / focal repo line, start mongod with systemd, connect with mongosh, install shell-only for Atlas, pin versions, and fix libssl1.1, AVX, and ECONNREFUSED errors described in Ask Ubuntu.
Tested on: Ubuntu 25.04 (Plucky Puffin); kernel 6.14.0-37-generic; amd64; MongoDB 8.0.26 from
noble/mongodb-org/8.0repo.
libssl1.1 dependency errors.
Quick command summary
| Task | Command |
|---|---|
| Check Ubuntu codename | lsb_release -cs |
| Check AVX support | grep flags -m1 /proc/cpuinfo | grep avx |
| Import GPG key (8.0) | curl -fsSL https://pgp.mongodb.com/server-8.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg |
| Add repo (24.04 noble) | echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list |
| Install full server | sudo apt update && sudo apt install -y mongodb-org |
| Shell only (Atlas / remote) | sudo apt install -y mongodb-mongosh |
| Enable and start | sudo systemctl enable --now mongod |
| Verify service | sudo systemctl status mongod |
| Connect locally | mongosh |
| Remove everything | sudo apt purge -y 'mongodb-org*' |
Prerequisites
- Ubuntu 20.04, 22.04, or 24.04 LTS (recommended). 25.04 tested with the noble repo workaround below.
- sudo and outbound HTTPS to
repo.mongodb.org. gnupgand cURL for the signed repository setup.- OpenSSL 3 on Ubuntu 22.04+ (see install OpenSSL on Ubuntu if
openssl versionfails). - Remove conflicting Ubuntu packages first:
sudo apt purge mongodbif installed.
What you are installing
| Package | Role |
|---|---|
mongodb-org |
Metapackage—server, shell, tools |
mongodb-org-server |
mongod daemon, /etc/mongod.conf, systemd unit |
mongodb-mongosh |
Modern mongosh shell (replaces legacy mongo) |
mongodb-org-shell |
Org shell metapackage slice (mongosh is separate package) |
mongodb-org-tools |
mongodump, mongorestore, mongoimport, etc. |
mongodb-database-tools |
Database tools binaries |
Data directory: /var/lib/mongodb (owner mongodb). Logs: /var/log/mongodb/mongod.log. Config: /etc/mongod.conf.
Choose Ubuntu codename and MongoDB version
| Ubuntu release | Codename | Repo path segment (8.0) |
|---|---|---|
| 24.04 LTS | noble |
noble/mongodb-org/8.0 |
| 22.04 LTS | jammy |
jammy/mongodb-org/8.0 |
| 20.04 LTS | focal |
focal/mongodb-org/8.0 |
| 25.04 (interim) | plucky |
Use noble until plucky repo exists (tested) |
For MongoDB 7.0 or 6.0, change 8.0 to the desired series in both the GPG URL (server-7.0.asc) and list file. This article tests 8.0.26 per the v8.0 install guide.
Do not point Ubuntu 22.04 at focal/mongodb-org/6.0—that was the root cause of libssl1.1 errors in 2022 forum posts. Use jammy on 22.04.
Step 1: Import the MongoDB GPG key
Install prerequisites:
sudo apt-get install -y gnupg curlImport the key into /usr/share/keyrings/ (replaces deprecated apt-key add):
curl -fsSL https://pgp.mongodb.com/server-8.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmorNo output means success. This matches current MongoDB documentation and avoids the Warning: apt-key is deprecated message from older tutorials.
Step 2: Add the official MongoDB repository
Pick one line for your release.
Ubuntu 24.04 (noble)—also used on tested 25.04:
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.listUbuntu 22.04 (jammy):
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.listUbuntu 20.04 (focal):
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.listReload indexes:
sudo apt-get update
apt-cache policy mongodb-orgExample on Ubuntu 25.04 using the noble repo:
mongodb-org:
Installed: (none)
Candidate: 8.0.26
Version table:
8.0.26 500
500 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0/multiverse amd64 PackagesStep 3: Install MongoDB Community Edition (full server)
Install the metapackage with apt:
sudo apt-get install -y mongodb-orgVerify packages:
dpkg -l | grep -i mongo
which mongod mongosh
mongod --version
mongosh --versionii mongodb-database-tools 100.17.0 amd64
ii mongodb-mongosh 2.8.3 amd64
ii mongodb-org 8.0.26 amd64
ii mongodb-org-server 8.0.26 amd64
ii mongodb-org-shell 8.0.26 amd64
ii mongodb-org-tools 8.0.26 amd64
/usr/bin/mongod
/usr/bin/mongosh
db version v8.0.26
...
"openSSLVersion": "OpenSSL 3.4.1 11 Feb 2025",
"environment": {
"distmod": "ubuntu2404",
"distarch": "x86_64"
}
2.8.3Pin a specific version (optional)
To prevent unintended upgrades (MongoDB docs):
sudo apt-get install -y \
mongodb-org=8.0.26 \
mongodb-org-database=8.0.26 \
mongodb-org-server=8.0.26 \
mongodb-org-shell=8.0.26 \
mongodb-org-mongos=8.0.26 \
mongodb-org-tools=8.0.26 \
mongodb-org-database-tools-extra=8.0.26Hold packages:
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-mongosh hold" | sudo dpkg --set-selectionsStep 4: Start mongod and enable at boot
sudo systemctl daemon-reload
sudo systemctl enable mongod
sudo systemctl start mongod
sudo systemctl status mongod● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; preset: enabled)
Active: active (running) since Thu 2026-06-25 12:24:21 IST; 7s ago
Docs: https://docs.mongodb.org/manual
Main PID: 1905188 (mongod)
└─1905188 /usr/bin/mongod --config /etc/mongod.confConfirm localhost binding:
ss -tlnp | grep 27017LISTEN 0 4096 127.0.0.1:27017 0.0.0.0:*By default bindIp: 127.0.0.1 in /etc/mongod.conf—remote hosts cannot connect until you change bind settings and enable authentication (production notes).
Step 5: Connect with mongosh and run a quick test
Wait a few seconds after the first start, then:
mongoshIf you see ECONNREFUSED, wait 2–5 seconds and retry—mongod was still initializing WiredTiger storage.
mongosh --quiet --eval "db.runCommand({ connectionStatus: 1 })"{
authInfo: { authenticatedUsers: [], authenticatedUserRoles: [] },
ok: 1
}List databases and insert a document:
mongosh --quiet --eval "show dbs"
mongosh --quiet --eval "db.test.insertOne({hello:'world'}); db.test.find"admin 40.00 KiB
config 12.00 KiB
local 40.00 KiB
[ { _id: ObjectId('6a3cd0dd9ab4614d059df8a3'), hello: 'world' } ]The legacy mongo shell no longer ships with MongoDB 6.0+ packages—use mongosh only (Ask Ubuntu).
Step 6: Install mongosh only (no local server)
When you use MongoDB Atlas or a remote cluster and only need the CLI client (Ask Ubuntu #1127055):
- Complete Step 1 and Step 2 (GPG key + repo).
- Install the shell package only:
sudo apt-get update
sudo apt-get install -y mongodb-mongoshOptional tools for backups without mongod:
sudo apt-get install -y mongodb-database-toolsConnect to Atlas:
mongosh "mongodb+srv://cluster.example.mongodb.net/mydb" --username myuserYou do not need mongodb-org-server or systemctl start mongod for cloud-only workflows.
Step 7: Install database tools
mongodb-org-tools (pulled in by mongodb-org) includes:
mongodump/mongorestoremongoimport/mongoexportmongostat/mongotop
Verify:
mongodump --versionInstall tools alone (after repo is configured):
sudo apt-get install -y mongodb-org-toolsUninstall MongoDB
Stop the service and purge packages (MongoDB docs):
sudo systemctl stop mongod
sudo apt-get purge -y 'mongodb-org*'
sudo rm -rf /var/lib/mongodb /var/log/mongodb
sudo rm -f /etc/apt/sources.list.d/mongodb-org-8.0.list
sudo rm -f /usr/share/keyrings/mongodb-server-8.0.gpg
sudo apt-get update
sudo apt-get autoremove -y # optionalThis permanently deletes all databases on the host. Back up with mongodump first. For reviewing orphaned dependencies after purge, see remove unused packages on Ubuntu.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Depends: libssl1.1 on Ubuntu 22.04 |
Wrong repo codename (focal on jammy) |
Use jammy/mongodb-org/X.Y in sources list—not focal; drop manual libssl1.1 .deb hacks |
apt-key is deprecated warning |
Old tutorial | Use gpg --dearmor → /usr/share/keyrings/mongodb-server-8.0.gpg with signed-by= |
Illegal instruction / core-dump on start |
CPU lacks AVX (MongoDB 5.0+) | grep avx /proc/cpuinfo; use MongoDB 4.4 or newer VM host |
ECONNREFUSED 127.0.0.1:27017 |
mongod still starting or not running | sudo systemctl status mongod; wait and retry; read /var/log/mongodb/mongod.log |
Conflicts with mongodb package |
Ubuntu universe package installed | sudo apt purge mongodb; install mongodb-org from official repo |
Package mongodb-org has no installation candidate |
Wrong codename or disabled multiverse | Match noble/jammy/focal; on 25.04 use noble |
| Remote clients cannot connect | Default bindIp: 127.0.0.1 |
Edit /etc/mongod.conf bind IP and enable auth before exposing to network |
soft rlimits too low warning |
Open file limit under 64000 | Raise ulimit -n per MongoDB production notes |
mongo: command not found |
Legacy shell removed | Install and use mongosh |
| Unintended version upgrade | apt tracks latest in repo | Pin version and dpkg --set-selections hold |
Optional: tarball install (advanced)
MongoDB publishes binary tarballs at mongodb.com/try/download/community. Use tarballs when you cannot use apt (air-gapped custom layout) or need a specific binary path. Typical flow:
sudo apt-get install -y libcurl4 openssl liblzma5
cd /tmpThe openssl package is usually preinstalled on Ubuntu—see install OpenSSL on Ubuntu if the tarball step fails with openssl: command not found.
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2404-8.0.26.tgz
tar -xzf mongodb-linux-x86_64-ubuntu2404-8.0.26.tgz
sudo cp mongodb-linux-*/bin/{mongod,mongos} /usr/local/bin/
sudo mkdir -p /var/lib/mongo /var/log/mongodb
sudo chown -R $USER /var/lib/mongo /var/log/mongodb
mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --forkInstall mongosh separately from the repo (mongodb-mongosh deb) or MongoDB Shell download. Prefer apt mongodb-org for systemd integration and supported upgrades.
References
- MongoDB 8.0 — Install on Ubuntu (official)
- Ask Ubuntu — Install shell without server
- MongoDB production notes
- On-site: apt command, sudo command
Summary
The supported way to install MongoDB on Ubuntu is the official mongodb-org repository: import the GPG key to /usr/share/keyrings/, add the list file with the correct noble, jammy, or focal codename, run sudo apt install -y mongodb-org, then sudo systemctl enable --now mongod. On Ubuntu 25.04, use the noble repo until plucky packages exist—8.0.26 installed and ran successfully in tests.
Connect with mongosh, not the removed mongo shell. For Atlas-only users, install mongodb-mongosh without the server. Avoid focal repos on jammy hosts, skip libssl1.1 workarounds on modern releases, and verify AVX before installing MongoDB 5.0+.

