How to Create MongoDB on VPS
MongoDB is a popular, high-performance NoSQL database used for modern applications that need flexible data models, fast reads/writes, and easy horizontal scaling. If you’re deploying an API, SaaS platform, CRM, e-commerce backend, or any data-driven service, running MongoDB on a VPS gives you full control over performance, security, and costs.
In this guide, you’ll learn how to install MongoDB Community Edition (latest supported release) on a Linux VPS using the official MongoDB repositories, start and enable the service, create users and databases, and apply essential security best practices (authentication, safe network binding, and firewall rules). The steps are written for production-style deployments and include common troubleshooting tips so you can get MongoDB running reliably from day one.
Prerequisites (quick checklist)
A VPS with root/sudo access
64-bit OS (MongoDB 8.0 supports Debian 12 Bookworm, Ubuntu LTS)
Recommended for production: read MongoDB’s production notes (filesystems, memory, ulimits, etc.)
Update your server first:
Important: don’t use the distro mongodb package (it can conflict with mongodb-org).
Install MongoDB on Debian 12 (Bookworm)
Add the official key + repository
echo "deb [signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg] https://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | \
sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list > /dev/nullInstall
(These commands are from MongoDB’s official Debian 12 install docs.)
Install MongoDB on Ubuntu LTS (24.04 / 22.04)
Add the official key + repository
Ubuntu 24.04 (Noble):
Ubuntu 22.04 (Jammy):
Install
Start MongoDB (and fix “mongod.service not found”)
MongoDB specifically notes daemon-reload if you see “Unit mongod.service not found”.
“Create” your database + users (recommended flow)
Open the shell locally on the VPS:
Create an admin user
In mongosh:
Create an application database + user
Secure MongoDB (don’t skip this)
MongoDB’s security checklist strongly recommends hardening before exposing anything.
A) Keep MongoDB private (best practice)
MongoDB warns to bind only to trusted networks.
In /etc/mongod.conf, ensure it listens only on localhost (or a private LAN IP):
