MirrorNest
← All guides

MongoDB Community Edition

A free, open-source, document-oriented NoSQL database -- installed from MongoDB's own official APT repository (not Ubuntu's default one, which typically lags behind).

Target: Ubuntu 22.04 LTS / 24.04 LTSDatabaseOfficial homepage ↗Official docs ↗
This guide is synthesized from MongoDB Community Edition's own official documentation, linked above — always cross-check exact package/version names there before running these commands on a production server, since distro and project versions move over time.
  1. 1Import MongoDB's official GPG key and repository

    curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg
    echo "deb [signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

    Check MongoDB's own install docs (linked above) for the current recommended version number -- this changes as new major versions are released.

  2. 2Install it

    sudo apt update
    sudo apt install mongodb-org
  3. 3Start and enable the service

    sudo systemctl start mongod
    sudo systemctl enable mongod
  4. 4Create an admin user

    mongosh
    use admin
    db.createUser({ user: "admin", pwd: "a-real-password", roles: ["root"] })

    MongoDB has no authentication enabled by default -- create this user, then enable `security.authorization: enabled` in /etc/mongod.conf and restart, or anyone who can reach the port has full access.