How to Install MongoDB on Debian 13 and Configure for Production Use

MongoDB is one of the most popular NoSQL databases, designed for applications that require high performance, flexibility, and scalability. Unlike traditional relational databases, MongoDB stores data in JSON-like BSON documents, making it an excellent choice for modern web applications, analytics platforms, and microservices. In this guide, we will teach you how to install MongoDB on Debian 13 and configure it for production use.

We will also show you how to secure it with authentication, configure it for production workloads, and perform basic administrative tasks. By the end of this guide, you will have a production-ready MongoDB server running on Debian 13.

Prerequisites

Before you begin, ensure you have:

Step 1. Update the System

First, update the package index and upgrade installed packages:

# apt update
# apt upgrade -y

Install the required packages:

 apt install -y curl gnupg

Step 2. Add the MongoDB Repository

MongoDB is not included in Debian’s default repositories. Add the official MongoDB repository.

Import the GPG key:

# curl -fsSL https://pgp.mongodb.com/server-8.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg

Add the MongoDB repository:

# echo "deb [signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg] https://repo.mongodb.org/apt/debian trixie/mongodb-org/8.0 main" | tee /etc/apt/sources.list.d/mongodb-org-8.0.list

Update the package list:

# apt update

Step 3. Install MongoDB

Install MongoDB Community Edition:

# apt install -y mongodb-org

Verify the installation:

# mongod --version

Example output:

# mongod --version
db version v8.0.26
Build Info: {
    "version": "8.0.26",
    "gitVersion": "a2c24805265db119cc39f2f54e067b4294a4ddd2",
    "openSSLVersion": "OpenSSL 3.5.6 7 Apr 2026",
    "modules": [],
    "allocator": "tcmalloc-google",
    "environment": {
        "distmod": "debian12",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }

Step 4. Start and Enable MongoDB

Start the MongoDB service:

sudo systemctl start mongod

Enable MongoDB to start automatically after reboot:

# systemctl enable mongod

Check the service status:

# systemctl status mongod

You should see:

systemctl status mongod

● mongod.service - MongoDB Database Server

Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; preset: >

Active: active (running) since Wed 2026-07-22 09:29:09 CEST; 4h 9min ago

Invocation: 96078d61a4044ceba22528bf21074f56

Docs: https://docs.mongodb.org/manual

Main PID: 2792 (mongod)

Memory: 236.7M (peak: 237.6M)

CPU: 3min 2.002s

CGroup: /system.slice/mongod.service

└─2792 /usr/bin/mongod --config /etc/mongod.conf

Jul 22 09:29:09 Debian13 systemd[1]: Started mongod.service - MongoDB Database >

Jul 22 09:29:10 Debian13 mongod[2792]: {"t":{"$date":"2026-07-22T07:29:10.778Z">

You can also check if MongoDB is listening on the default port with:

# ss -tulpn | grep 27017

Expected output:

tcp LISTEN 0 4096 127.0.0.1:27017 0.0.0.0:* users:(("mongod",pid=2792,fd=9))

By default, MongoDB only listens on localhost, which is recommended unless remote access is required.

Step 5. Create an Administrator Account

Open the MongoDB shell:

# mongosh

Now switch to the admin database:

use admin

And to create the Administrator, use the following command, where you can change the username and Password:

db.createUser({

user: "newadmin",

pwd: "SomeStrongPass",

roles: [

{ role: "userAdminAnyDatabase", db: "admin" },

{ role: "dbAdminAnyDatabase", db: "admin" },

{ role: "readWriteAnyDatabase", db: "admin" }

]

})

And exit the shell with:

exit

Step 6. Enable Authentication


The user was created previously, but to enable authentication, you will need to edit the MongoDB configuration:

# nano /etc/mongod.conf

Find or add the security section:

security:
  authorization: enabled

Save the file and restart MongoDB:

systemctl restart mongod

Now you can test this by logging in using the administrator account:

# mongosh -u newadmin -p --authenticationDatabase admin

Enter the password when prompted. And you should be logged in now. You should see a similar output:

Current Mongosh Log ID: 6a60ad595156680574956f1a
Connecting to:          mongodb://<credentials>@127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&authSource=admin&appName=mongosh+2.9.2
Using MongoDB:          8.0.26
Using Mongosh:          2.9.2

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

test>

Step 7. Configure WiredTiger Cache

The WiredTiger storage engine is the default in MongoDB; it automatically allocates approximately half of the available RAM to the WiredTiger cache.

For dedicated database servers, you may wish to explicitly configure the cache size.

Edit the configuration:

# nano /etc/mongod.conf

Then you can add:

storage:
  wiredTiger:
    engineConfig:
      cacheSizeGB: 2

Adjust the value according to your available memory and go ahead and restart MongoDB:

# systemctl restart mongod

Step 8: Set Up Automated Backups

A production database without backups is a production incident waiting to happen. A simple, reliable approach is a nightly mongodump via cron:

# mkdir -p /var/backups/mongodb

# crontab -e

Add a line to run a dump every night at 2 a.m., keeping a dated folder:

0 2 * * * mongodump --username siteAdmin --authenticationDatabase admin --out /var/backups/mongodb/$(date +\%F) --gzip

Conclusion

It is also useful to set up logging and increase the file descriptor limits, but this is already done by default on MongoDB 8; the limits are increased directly in the systemctl service file, and logging is enabled by default in the /etc/mongod. confconf file.

For High Availability, you should consider running a replica set, with a minimum of 3 nodes, even if you don’t need read scaling. It’s your main defense against a single point of failure and enables safer maintenance (rolling restarts and no-downtime upgrades).

You will also need to size the oplog appropriately – the default is often too small for high-write workloads. Undersized oplogs mean secondaries can’t catch up after downtime, requiring a full resync.

In this tutorial, you learned how to install MongoDB on Debian 13 and configure it for production use. If you still need assistance, you can always find a reputable Linux MSP.

If you enjoyed this post on installing MongoDB on Debian 13, please share it with your friends or leave a comment below.

Leave a Comment