Skip to content
Runbook

Install MongoDB on Ubuntu / Debian

Document-oriented NoSQL database (BSON), designed for horizontal scalability and flexible schemas.

Databasenosqldocumentdatabasebson

Installation

Server (official repository) · apt
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
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
sudo apt-get update
sudo apt-get install -y mongodb-org

For Debian, replace the repository with the Debian one (e.g. bookworm); the apt "mongodb" package from the default repositories is outdated.

Verify the installation

Verify
mongod --version

Service

Start
sudo systemctl start mongod
Stop
sudo systemctl stop mongod
Status
sudo systemctl status mongod
Restart
sudo systemctl restart mongod
On boot
sudo systemctl enable mongod

Important files

TypePathDescription
config/etc/mongod.confServer configuration (YAML).
data/var/lib/mongodbdbPath data directory.
log/var/log/mongodb/mongod.logServer log.

Default ports

27017

Command-line tools

  • mongoshAdministration and query shell.
  • mongodumpBinary export of a database.
  • mongorestoreRestore of a binary dump.

Uninstall

Uninstall (and purge)
sudo systemctl stop mongod
sudo apt-get purge -y mongodb-org*
sudo rm -r /var/lib/mongodb /var/log/mongodb

Purging the directories permanently removes your data.

Good to know

  • The mongodb-org meta-package installs the server, mongosh and the mongodb-database-tools.
  • Adapt the distribution name ("noble" for Ubuntu 24.04) to your version.
  • Security: by default authentication is disabled and the server listens only on 127.0.0.1. Never expose port 27017 without enabling security.authorization and restricting net.bindIp.

Installation on Ubuntu / Debian

MongoDB publishes its own APT repository, which should be preferred over the distribution's packages (often several major versions behind). The installation block adds the GPG key, declares the repository, then installs the mongodb-org meta-package.

The mongod service starts via systemd; enable it at boot with systemctl enable mongod. The configuration lives in /etc/mongod.conf.