DevOps
Install MongoDB 7.0 on Ubuntu Server: Official APT & systemd Setup
Install MongoDB Community 7 via mongodb-org packages on Ubuntu Server: gpg signing key import, MongoDB-maintained apt source pointing at repo.mongodb.org, systemd start enable mongod, then pair the same VPS with nginx frontends via the shared apt patterns I keep in snippets.

MongoDB shines when schemas refuse to stabilize up front yet you still crave replica sets and sane ops paths. Ubuntu Server installs become predictable once you abandon ancient universe packages for mongodb-org, wire systemd, and optionally stack the DB tier behind tools that reuse the familiar apt, systemctl, and UFW cadence—you will see parallel steps in the nginx install command slab whenever the same host also terminates HTTP.
⏱️ Estimated setup time: 10–15 minutes.
Update Ubuntu packages safely
Bring the base image forward so gpg and mongodb tooling land on sane dependency chains.
sudo apt-get update && sudo apt-get upgrade
This pass can chew a few minutes if the box has slept through patch Tuesday.
Install gpg and curl for apt sources
You need gpg for keyring exports and curl to fetch ASCII keys cleanly.
sudo apt-get install gnupg curl
Pull the MongoDB 7 signing key
Drop MongoDB upstream signing material into Debian-style keyrings so apt verifies package indexes.
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
Wire up the MongoDB APT repository entry
Jammy aligns with Ubuntu 22.04 LTS; Noble maps to Ubuntu 24.04 LTS. Pick the MongoDB line that matches your LTS codename—the pattern below preserves arch=amd64,arm64 plus the keyring anchor.
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
Reload apt caches after adding the repo
Let apt ingest the fingerprinted index.
sudo apt-get update
Install the mongodb-org metapackage
The metapackage groups server shell and companion bits you normally want together.
sudo apt-get install -y mongodb-org
Pulling mongodb-org can take longer on cold mirrors because every component lands in parallel.
Start MongoDB and enable systemd
Kick the daemon on immediately, then insist systemd resurrects mongod after reboot cycles.
sudo systemctl start mongod
sudo systemctl enable mongod
Check the MongoDB daemon version
mongod --version
You should spot the 7.0.x stamping that proves you pulled Community bits through upstream packaging.
Paths, logs, mongosh pairing with nginx VMs
- Main config:
/etc/mongod.conf(bind IPs, journaling, WiredTiger knobs) - Default wire port:
27017 - Data directory:
/var/lib/mongodb - Log directory:
/var/log/mongodb
Drop into data exploration anytime with mongosh.
Frequently asked questions
Why import the MongoDB GPG key before apt installs mongodb-org?
Ubuntu apt cryptographically verifies package indexes signed by distributors. Installing the MongoDB server GPG key under /usr/share/keyrings lets apt trust MongoDB repository metadata rather than blindly ingesting arbitrary third-party debs.
The APT source line cites jammy; what codename does my Ubuntu LTS release use?
Jammy Jellyfish aligns with Ubuntu 22.04 LTS and matches the documented mongodb-org 7 listing. Noble aligns with Ubuntu 24.04 LTS. Swap jammy for the codename MongoDB documents for your LTS tier so apt resolves mongodb-org 7 cleanly from repo.mongodb.org.
Which systemd commands start MongoDB immediately and survive reboots?
Run sudo systemctl start mongod to boot the daemon now and sudo systemctl enable mongod to register the systemd unit so it returns automatically after reboots.
Where does Ubuntu keep MongoDB configs data and telemetry logs?
Configuration resides in /etc/mongod.conf, database payloads live under /var/lib/mongodb, and runtime telemetry streams to /var/log/mongodb with mongod.log as your first troubleshooting stop.
What should I do after install before trusting the instance publicly?
Tune bindIp, authentication, backups, and firewall posture before workloads connect remotely. Provision admin credentials and rethink remote sockets only after tightening network policy around port 27017.
You now carry the apt plus systemd spine for mongodb-org 7. When log noise grows, skim mongod output under /var/log/mongodb, reconcile firewall intent with the nginx command snippet, then graduate into hardened users and constrained exposure paths.
Written by Shashikant Dwivedi
Engineer, occasional writer, full-time noticer. Based in Prayagraj, India. New essays land roughly twice a month.
Keep reading
Adjacent essays.

DevOps
How to Install MySQL 8 on Ubuntu Server: APT, systemd, and first lockdown
Dec 24, 2024 · 6 min

DevOps
Install Nginx on Ubuntu Server: apt, UFW, systemd, welcome page
Sep 14, 2024 · 5 min

DevOps
Install Redis on Ubuntu Server: Official APT Repo & Remote Access
Sep 1, 2025 · 5 min
The newsletter
New articles in your inbox.
Occasional articles on engineering, tooling, and software development practices. No marketing, no fluff — just the article, when it's ready.
Unsubscribe with one click. Your email never leaves the list.