MongoDB Installation Guide

Version Selection and Platform Requirements

Version Selection

MongoDB currently has two major version series:

  • MongoDB 8.2: Latest stable release, recommended for new projects
  • MongoDB 7.0: Long-term support version, suitable for production environments requiring stability

Starting with MongoDB 8.2, minor releases are available for specific use cases in on-premises deployments.

Platform Requirements

  • MongoDB no longer supports 32-bit platforms. Please ensure your operating system is 64-bit
  • MongoDB 6.0 reached end of life on July 31, 2025 and no longer receives security updates

Supported Platforms

MongoDB Community Edition supports the following platforms and architectures:

Ubuntu

  • Ubuntu 24.04 (x86_64, arm64)
  • Ubuntu 22.04 (x86_64, arm64)
  • Ubuntu 20.04 (x86_64, arm64)

Debian

  • Debian 12 (x86_64)
  • Debian 11 (x86_64)

RHEL/CentOS/Rocky Linux

  • RHEL/Rocky/Alma/Oracle Linux 9.0+ (x86_64, arm64)
  • RHEL/Rocky/Alma/Oracle Linux 8.0+ (x86_64, arm64, ppc64le, s390x)
  • RHEL/Oracle Linux 7.0+ (x86_64)

macOS

  • macOS 14 (x86_64, arm64)
  • macOS 13 (x86_64, arm64)
  • macOS 12 (x86_64, arm64)
  • macOS 11 (x86_64, arm64)

Windows

  • Windows 11 (x86_64)
  • Windows Server 2022 (x86_64)
  • Windows Server 2019 (x86_64)

Other Linux

  • Amazon Linux 2023 (x86_64, arm64)
  • Amazon Linux 2 (x86_64, arm64)
  • SLES 15 (x86_64)
  • SLES 12 (x86_64)

Install MongoDB Community Edition on Ubuntu

Step 1: Import the Public Key

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

Step 2: Create the MongoDB Repository List File

Choose the appropriate configuration based on your Ubuntu version:

Ubuntu 24.04 (Noble):

echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian noble/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

Ubuntu 22.04 (Jammy):

echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian jammy/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

Ubuntu 20.04 (Focal):

echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian focal/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

Step 3: Update the Package List

sudo apt update

Step 4: Install MongoDB

Install the latest version:

sudo apt install -y mongodb-org

Or install a specific version:

sudo apt install -y mongodb-org=8.0.0 mongodb-org-server=8.0.0 mongodb-org-shell=8.0.0 mongodb-org-mongos=8.0.0 mongodb-org-tools=8.0.0

Step 5: Start MongoDB

Start the mongod service:

sudo systemctl start mongod

Enable automatic startup:

sudo systemctl enable mongod

Install MongoDB Community Edition on Debian

Step 1: Import the Public Key

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

Step 2: Create the Repository

Debian 12 (Bookworm):

echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

Debian 11 (Bullseye):

echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

Step 3: Update and Install

sudo apt update
sudo apt install -y mongodb-org

Install on RHEL/CentOS/Rocky Linux

Install Using YUM/DNF

Step 1: Create the Repository File

Create the /etc/yum.repos.d/mongodb-org.repo file:

[mongodb-org-8.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/8.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-8.0.asc

Step 2: Install MongoDB

Using DNF (recommended):

sudo dnf install -y mongodb-org

Or using YUM:

sudo yum install -y mongodb-org

Step 3: Start MongoDB

sudo systemctl start mongod
sudo systemctl enable mongod

Install on macOS

Install Using Homebrew

Step 1: Update Homebrew

brew update

Step 2: Install MongoDB

brew install mongodb-community

Step 3: Start MongoDB

Start as a background service (recommended):

brew services start mongodb-community

Or run manually:

mongod --config /usr/local/etc/mongod.conf

Step 4: Stop MongoDB

brew services stop mongodb-community

Manual Installation

Step 1: Download MongoDB

curl -O https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-8.0.0.tgz

For ARM64 architecture:

curl -O https://fastdl.mongodb.org/osx/mongodb-macos-arm64-8.0.0.tgz

Step 2: Extract

tar -zxvf mongodb-macos-*.tgz

Step 3: Move Binary Files

sudo mkdir -p /usr/local/bin
sudo cp mongodb-macos-*/bin/* /usr/local/bin/

Step 4: Create the Data Directory

sudo mkdir -p /data/db
sudo chown -R $(whoami) /data/db

Step 5: Start MongoDB

mongod --dbpath /data/db

Install on Windows

Using MSI Installer

  1. Download the Windows MSI installer from the MongoDB Download Center
  2. Run the installer and follow the wizard steps
  3. Select "Complete" installation type to install all components
  4. After installation, MongoDB is automatically installed as a Windows service

Using ZIP Package

Step 1: Download MongoDB

Download the Windows ZIP package from the MongoDB Download Center.

Step 2: Extract

Extract the files to your target directory, for example C:\Program Files\MongoDB.

Step 3: Create the Data Directory

mkdir C:\data\db

Step 4: Start MongoDB

"C:\Program Files\MongoDB\Server\8.0\bin\mongod.exe" --dbpath C:\data\db

Install Using Docker

Install MongoDB Community Edition

Step 1: Pull the Image

docker pull mongodb/mongodb-community-server

Step 2: Run the Container

docker run --name mongodb -d -p 27017:27017 mongodb/mongodb-community-server

Data Persistence

To persist data, use volume mounting:

docker run --name mongodb -d -p 27017:27017 -v mongodb_data:/data/db mongodb/mongodb-community-server

Using Docker Compose

Create a docker-compose.yml file:

version: '3.8'
services:
  mongodb:
    image: mongodb/mongodb-community-server
    container_name: mongodb
    ports:
      - "27017:27017"
    volumes:
      - mongodb_data:/data/db
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_ROOT_PASSWORD=yourpassword

volumes:
  mongodb_data:

Start:

docker-compose up -d

Verify Installation

Connect to MongoDB

After installation, use mongosh (MongoDB Shell) to connect:

mongosh

If the connection is successful, you will see the MongoDB interactive shell prompt.

Check the Version

Check the version in mongosh:

db.version()

Basic Commands

# View databases
show dbs

# Switch database
use test

# View current database
db

# View help
db.help()

Post-Installation Configuration

Create an Administrator User

Execute in mongosh:

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

Enable Authentication

  1. Stop the MongoDB service
  2. Modify /etc/mongod.conf to enable authentication:
security:
  authorization: enabled
  1. Restart the MongoDB service:
sudo systemctl restart mongod

Configure Remote Connections

  1. Modify the network configuration in /etc/mongod.conf:
net:
  port: 27017
  bindIp: 0.0.0.0
  1. Restart the MongoDB service

  2. Open the port in the firewall:

sudo ufw allow 27017

Uninstall MongoDB

Ubuntu/Debian

sudo apt remove --purge mongodb-org
sudo rm -rf /var/lib/mongodb
sudo rm -rf /var/log/mongodb
sudo rm -rf /etc/mongod.conf

macOS (Homebrew)

brew uninstall mongodb-community
brew services stop mongodb-community
rm -rf /usr/local/etc/mongod.conf
rm -rf /data/db

RHEL/CentOS

sudo yum remove -y mongodb-org
sudo rm -rf /var/lib/mongo
sudo rm -rf /var/log/mongodb

Windows

Uninstall MongoDB through the Control Panel's "Programs and Features", then manually delete the data directory.

Frequently Asked Questions

What is the default port for MongoDB?

The default port is 27017. You can also specify a different port using the --port parameter.

Where does MongoDB store data?

By default:

  • Linux/macOS: /data/db
  • Windows: C:\data\db

You can change this by modifying storage.dbPath in the configuration file.

How to check MongoDB running status?

sudo systemctl status mongod

Or in mongosh:

db.adminCommand({ ping: 1 })