Cloud Hosting

How to Install MongoDB on a VPS

A step-by-step Ubuntu guide to setting up MongoDB — a powerful NoSQL database widely used in modern web and mobile apps.

InviSofts EngineeringFeb 02, 20269 min
How to Install MongoDB on a VPS

MongoDB is a powerful NoSQL database used widely in modern web and mobile applications. Installing it on an Ubuntu VPS takes just a few minutes if you follow the right steps.

Step 1 — Import the public key: curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor

Step 2 — Add the MongoDB repository: echo "deb [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

Step 3 — Install: sudo apt update && sudo apt install -y mongodb-org. Then enable and start the service with sudo systemctl enable --now mongod.

Step 4 — Secure your installation: enable authentication in /etc/mongod.conf, create an admin user, configure your firewall (ufw), and bind only to private IPs in production.

Once running, you can connect via mongosh or your preferred MongoDB client. For high-traffic production workloads, consider replica sets and managed backups.

Free consultation

Ready to grow with modern technology?

Tell us about your goals — our IT specialists will share a roadmap and proposal within one business day.