Skip to main content

Install MongoDB on Linux

· One min read
Apache Wangye
Software developer and technical writer

Install MongoDB from the official repository for your distribution whenever possible. Repository packages provide service files, upgrades, and dependency management.

After installation, review /etc/mongod.conf:

storage:
dbPath: /var/lib/mongodb
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
logAppend: true
net:
port: 27017
bindIp: 127.0.0.1

Start and enable the service:

sudo systemctl enable --now mongod
sudo systemctl status mongod

Connect locally:

mongosh

Create an administrator before enabling authorization, then set:

security:
authorization: enabled

Restart MongoDB and verify authenticated access. Do not bind 0.0.0.0 or expose port 27017 publicly without authentication, firewall restrictions, TLS, backups, and monitoring. Ensure the data directory is owned by the MongoDB service account and has enough capacity.

Page views: --

Total views -- · Visitors --