MongoDBInstallation

Installing MongoDB

MongoDB Community Edition is free and open-source. This guide covers installing on Windows, macOS, and Linux (Ubuntu/Debian).

System Requirements

OS

Min RAM

Min Disk

Architecture

Windows 10+

4 GB

10 GB

x86_64

macOS 10.14+

4 GB

10 GB

x86_64, arm64

Ubuntu 20.04+

4 GB

10 GB

x86_64

Installing on Windows
  1. Go to mongodb.com/try/download/community

  2. Select version 7.x, Windows, .msi

  3. Run the installer and choose Complete installation

  4. Check "Install MongoDB as a Service"

  5. Install MongoDB Compass when prompted

Verify installation on Windows

Text
mongod --version
mongosh --version
Installing on macOS (Homebrew)

Install via Homebrew

Bash
# Add the MongoDB tap
brew tap mongodb/brew

# Install MongoDB Community Edition
brew install mongodb-community

# Start the MongoDB service
brew services start mongodb-community

# Connect using the shell
mongosh
Installing on Ubuntu/Debian

Install on Ubuntu 22.04

Bash
# Import the MongoDB public GPG 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

# Add the repository
echo "deb [ arch=amd64,arm64 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

# Update and install
sudo apt-get update
sudo apt-get install -y mongodb-org

# Enable and start the service
sudo systemctl enable mongod
sudo systemctl start mongod

# Check the status
sudo systemctl status mongod
Creating the Data Directory (Linux/macOS)

Bash
mkdir -p /data/db
sudo chown -R `id -un` /data/db
Configuration File

MongoDB reads its configuration from a YAML file at startup. Default locations are /etc/mongod.conf on Linux, /usr/local/etc/mongod.conf on macOS (Homebrew), and C:\Program Files\MongoDB\Server\7.0\bin\mongod.cfg on Windows.

/etc/mongod.conf

YAML
# mongod.conf — basic configuration

# Data storage
storage:
  dbPath: /var/lib/mongodb

# Logging
systemLog:
  destination: file
  path: /var/log/mongodb/mongod.log
  logAppend: true

# Network
net:
  port: 27017
  bindIp: 127.0.0.1

# Process management
processManagement:
  timeZoneInfo: /usr/share/zoneinfo
Verifying the Installation

Connect and verify

Bash
# Open the MongoDB shell
mongosh

# Check the server version
db.version()

# List databases
show dbs

# Ping the server
db.runCommand({ ping: 1 })
Note
The data directory /data/db must exist and be writable before starting mongod. If it does not exist, mongod will refuse to start.
Tip
For development, MongoDB Atlas (cloud) requires zero installation — just create a free account at cloud.mongodb.com and connect in seconds.
Warning
Never run mongod as root in production. Create a dedicated mongodb system user and ensure only that user owns the data directory.