serverOwn Machine

This guide explains how to install MongoDB Community Edition on Ubuntu using the official MongoDB repository.

⚠️ These steps work for Ubuntu 20.04, 22.04, and 24.04.


Update Your System

sudo apt update && sudo apt upgrade -y

Install Required Dependencies

sudo apt install -y gnupg curl

Import MongoDB Public GPG Key

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

Add the MongoDB Repository

Ubuntu 24.04 (Noble)

echo "deb [ arch=amd64 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

Ubuntu 22.04 (Jammy)

echo "deb [ arch=amd64 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

Ubuntu 20.04 (Focal)


Update Package List


Install MongoDB

This installs: - mongod (MongoDB server) - mongosh (MongoDB shell) - MongoDB tools


Start MongoDB Service


Check Service Status

You should see:


Test MongoDB

Inside the shell:

Exit:


  1. Edit the config file:

  1. Add:

  1. Restart MongoDB:

  1. Create an admin user:


Optional: Allow Remote Connections

  1. Edit config file:

  1. Change:

To:

  1. Restart MongoDB:

  1. Open firewall (if using UFW):

circle-exclamation

MongoDB should now be installed and running successfully on your Ubuntu server.

Last updated