Back to blog
May 23, 2026Guides

How to Install MongoDB on Linux VPS

Install MongoDB Community Edition on Ubuntu and CentOS, enable authentication, and run basic commands.

How to Install MongoDB on Linux VPS

MongoDB is a popular NoSQL database for modern apps, APIs, and analytics. This guide installs MongoDB on your Hiddence VPS and covers basic security setup.

Install on Ubuntu 22.04+

bash
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
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
sudo apt update
sudo apt install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod
mongosh --eval "db.runCommand({ ping: 1 })"

Install on RHEL / CentOS / Alma / Rocky

bash
cat <<EOF | sudo tee /etc/yum.repos.d/mongodb-org-7.0.repo
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
EOF
sudo yum install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod

Enable authentication

Create an admin user before exposing MongoDB to the network:

bash
mongosh

use admin
db.createUser({
  user: "admin",
  pwd: "StrongPasswordHere",
  roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
})

# Edit /etc/mongod.conf — set:
# security:
#   authorization: enabled

sudo systemctl restart mongod

Basic commands

bash
mongosh -u admin -p --authenticationDatabase admin

show dbs
use myapp
db.users.insertOne({ name: "test", email: "a@b.com" })
db.users.find()

Best practices

  • Bind MongoDB to 127.0.0.1 unless remote access is required
  • Use firewall to block port 27017 from the internet
  • Enable regular backups with mongodump
  • Monitor disk space — databases grow quickly
  • Use replica sets for production high availability