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
Go to mongodb.com/try/download/community
Select version 7.x, Windows, .msi
Run the installer and choose Complete installation
Check "Install MongoDB as a Service"
Install MongoDB Compass when prompted
Verify installation on Windows
mongod --version mongosh --version
Installing on macOS (Homebrew)
Install via Homebrew
# 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
# 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)
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
# 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
# Open the MongoDB shell
mongosh
# Check the server version
db.version()
# List databases
show dbs
# Ping the server
db.runCommand({ ping: 1 })