MongoDB 7.0 is a leading NoSQL document database that stores data as flexible JSON-like documents. This guide installs it on Ubuntu 24.04 LTS from the official MongoDB repository.

Tested and valid on:

  • Ubuntu 24.04 LTS

Prerequisites

  • Ubuntu 24.04 LTS server
  • A user with sudo privileges

Step 1 – Import the MongoDB GPG Key

Add the official signing key:

curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor

Step 2 – Add the MongoDB Repository

Add the MongoDB 7.0 repo for Ubuntu 24.04 (noble):

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

Step 3 – Install MongoDB

Update and install:

sudo apt update
sudo apt install mongodb-org -y

Step 4 – Start and Enable MongoDB

Start the mongod service:

sudo systemctl start mongod
sudo systemctl enable mongod

Step 5 – Verify the Service

Check service status:

sudo systemctl status mongod

Step 6 – Connect to MongoDB

Open the MongoDB shell:

mongosh

Inside the shell, create a database and user:

use mydb
db.createUser({ user: 'myuser', pwd: 'StrongPassword123!', roles: [{ role: 'readWrite', db: 'mydb' }] })

Step 7 – Enable Authentication

Edit the MongoDB config to require authentication:

sudo nano /etc/mongod.conf

Add under the security section:

security:
  authorization: enabled

Restart MongoDB:

sudo systemctl restart mongod

Step 8 – Check the Version

Verify the installed version:

mongod --version

Conclusion

MongoDB 7.0 is now installed and secured on Ubuntu 24.04 LTS. With authentication enabled, only authorised users can access databases. MongoDB is ideal for applications that need flexible schemas and horizontal scaling.