Install MongoDB on Ubuntu via the official MongoDB apt repo. Add the GPG key, configure the repo, install mongodb-org. The team that uses the official repo has the latest version. The team that uses Ubuntu’s older mongodb package has the deprecated version.
Table of contents
- Add MongoDB’s GPG key and repo
- Install
- Start and enable
- Verify
- Secure the install
- Configure data and log paths
- Backup
- FAQ
Add MongoDB’s GPG key and repo
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg
echo "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" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt update
On Ubuntu 22.04 (jammy), on 24.04 (noble) the codename is different.
Install
sudo apt install mongodb-org
This installs mongod, mongos, mongo shell, and tools.
Start and enable
sudo systemctl enable --now mongod
sudo systemctl status mongod
The team that enables the service has MongoDB start at boot.
Verify
mongosh
# Inside mongosh:
> db.runCommand({ ping: 1 })
> show dbs
> exit
The team that sees ping succeed has working install.
Secure the install
- Bind to localhost (default) or specific IP, not 0.0.0.0.
- Enable auth: in
/etc/mongod.conf:
security:
authorization: enabled
- Create admin user:
use admin
db.createUser({
user: 'admin',
pwd: 'strong_password',
roles: [{ role: 'userAdminAnyDatabase', db: 'admin' }]
})
The team that enables auth has authenticated MongoDB. The team that runs without auth on a public IP has data leaks.
Configure data and log paths
Edit /etc/mongod.conf:
storage:
dbPath: /var/lib/mongodb
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
net:
port: 27017
bindIp: 127.0.0.1
The team that has config management has version-controlled MongoDB config.
Backup
Use mongodump for logical backups:
mongodump --uri="mongodb://localhost:27017" --out=/backup/$(date +%Y%m%d)
For hot backups, use mongodb-consistent-backup or filesystem snapshots (with WiredTiger). The team that has scheduled backups has recovery.
FAQ
What’s the latest MongoDB version?
MongoDB 8.0 (as of 2026). 7.0 is also widely used. Use 8.0 for new deployments.
What’s the default port for MongoDB?
Can I install MongoDB on Ubuntu 24.04?
Yes - use the noble codename in the apt repo. The team that uses the right codename has working installs.
Should I use Ubuntu’s mongodb package?
No - it’s deprecated (Ubuntu dropped it). Use MongoDB’s official repo.
What about MongoDB Atlas?
MongoDB’s managed cloud service. The team that uses Atlas has no install, no ops. The team that needs on-prem uses self-hosted.
If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.
Useful related references: