Section 2: Installation

🍎 MongoDB macOS Installation

Complete step-by-step guide to install MongoDB Server on macOS - Intel and Apple Silicon (M1/M2/M3)

2 Installation Methods
5min Setup Time
100% Free & Open Source
M1/M2/M3 Apple Silicon Ready
πŸ“–

Installation Overview

Choose your installation method

πŸ’‘ About This Guide

This guide covers two methods to install MongoDB Community Edition on macOS: Homebrew (recommended, easiest) and Manual Installation (more control). Both methods work on Intel Macs and Apple Silicon (M1/M2/M3).

🍺
Homebrew
Easy, one-command installation using Homebrew package manager. Automatic updates and dependency management.
βœ… Recommended
πŸ“¦
Manual
Download and install MongoDB manually. More control over installation location and configuration.
βš™οΈ Advanced
βœ…

System Requirements

What you need

  • macOS Version: 10.14 (Mojave) or later
  • Chip Support: Intel x86_64 or Apple Silicon (M1/M2/M3)
  • RAM: Minimum 4 GB (8 GB+ recommended)
  • Disk Space: 5 GB free space minimum
  • Xcode Command Line Tools: Required for Homebrew
πŸ’‘ Check Your Mac Chip

Click the Apple menu β†’ About This Mac

  • Intel Mac: Shows "Processor: Intel Core i5/i7/i9"
  • Apple Silicon: Shows "Chip: Apple M1/M2/M3"
🍺

Method 1: Homebrew Installation

Recommended - Easiest method

βœ… Why Use Homebrew?
  • One-command installation
  • Automatic dependency management
  • Easy updates with brew upgrade
  • Works perfectly on Intel and Apple Silicon
  • Widely used and community-supported
0
Install Homebrew (if needed)

If you don't have Homebrew installed, install it first:

Terminal
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Check if Homebrew is installed:

Terminal
$ brew --version
Homebrew 4.2.0
1
Add MongoDB Tap

Add the MongoDB Homebrew repository (tap):

Terminal
$ brew tap mongodb/brew
==> Tapping mongodb/brew Cloning into '/opt/homebrew/Library/Taps/mongodb/homebrew-brew'... Tapped 13 formulae (40 files, 45.7KB).
πŸ’‘ What is a "tap"? A tap is a third-party Homebrew repository. The MongoDB tap contains official MongoDB packages.
2
Install MongoDB Community

Install the latest MongoDB Community Edition:

Terminal
$ brew install mongodb-community
==> Downloading mongodb-community@7.0 ==> Downloading mongodb-database-tools ==> Downloading mongosh ==> Installing mongodb-community ==> Installing dependencies: mongodb-database-tools, mongosh ... 🍺 /opt/homebrew/Cellar/mongodb-community/7.0.5: 12 files, 186.3MB
⚠️ Apple Silicon Note On M1/M2/M3 Macs, Homebrew installs to /opt/homebrew
On Intel Macs, Homebrew installs to /usr/local
βœ… Installation Complete! MongoDB is now installed. The installation includes mongod (server), mongosh (shell), and database tools.
3
Start MongoDB Service

Start MongoDB as a macOS service:

Terminal
# Start MongoDB (runs in background) $ brew services start mongodb-community
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
# Check if running $ brew services list
Name Status User File mongodb-community started yourusername ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
πŸ’‘ Alternative: Start Manually If you prefer to start MongoDB manually (foreground):
$ mongod --config /opt/homebrew/etc/mongod.conf
Service Management Commands
Homebrew Services
# Start MongoDB $ brew services start mongodb-community # Stop MongoDB $ brew services stop mongodb-community # Restart MongoDB $ brew services restart mongodb-community # Check status $ brew services list # Update MongoDB $ brew upgrade mongodb-community
πŸ“¦

Method 2: Manual Installation

For advanced users

⚠️ Advanced Method

This method gives you more control but requires manual configuration. If you're new to MongoDB, we recommend the Homebrew method above.

1
Download MongoDB

Visit the MongoDB Download Center and download the appropriate version:

Choose your chip type:

  • macOS ARM64 for Apple Silicon (M1/M2/M3)
  • macOS x64 for Intel Macs
πŸ’‘ File Format Download the .tgz (tarball) file. It will be named something like: mongodb-macos-arm64-7.0.5.tgz or mongodb-macos-x86_64-7.0.5.tgz
2
Extract and Move Files

Extract the downloaded tarball and move it to a permanent location:

Terminal
# Navigate to Downloads $ cd ~/Downloads # Extract (replace with your actual filename) $ tar -zxvf mongodb-macos-arm64-7.0.5.tgz # Move to /usr/local $ sudo mv mongodb-macos-arm64-7.0.5 /usr/local/mongodb
3
Add MongoDB to PATH

Add MongoDB binaries to your system PATH:

Terminal
# For Zsh (default on macOS Catalina+) $ echo 'export PATH="/usr/local/mongodb/bin:$PATH"' >> ~/.zshrc $ source ~/.zshrc # For Bash (older macOS versions) $ echo 'export PATH="/usr/local/mongodb/bin:$PATH"' >> ~/.bash_profile $ source ~/.bash_profile # Verify $ mongod --version
db version v7.0.5 Build Info: { "version": "7.0.5", ... }
4
Create Data and Log Directories

MongoDB needs directories for data storage and logs:

Terminal
# Create data directory $ sudo mkdir -p /usr/local/var/mongodb # Create log directory $ sudo mkdir -p /usr/local/var/log/mongodb # Set permissions (replace 'yourusername' with your actual username) $ sudo chown yourusername /usr/local/var/mongodb $ sudo chown yourusername /usr/local/var/log/mongodb
πŸ’‘ Find Your Username Run whoami in Terminal to see your current username.
5
Start MongoDB

Start MongoDB manually with custom paths:

Terminal
$ mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
about to fork child process, waiting until server is ready for connections. forked process: 12345 child process started successfully, parent exiting
πŸ’‘ Command Options
  • --dbpath: Where to store database files
  • --logpath: Where to write logs
  • --fork: Run as background process
βœ“

Verify Installation

Test MongoDB is working

Connect Using MongoDB Shell
MongoDB Shell
$ mongosh
Current Mongosh Log ID: 657b3a4c9e8a7b2c3d4e5f6a Connecting to: mongodb://127.0.0.1:27017 Using MongoDB: 7.0.5 Using Mongosh: 2.1.1 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ test>
# Check version test> db.version()
7.0.5
# Test insert test> db.test.insertOne({ message: "Hello from macOS!", chip: "M2" })
{ acknowledged: true, insertedId: ObjectId('657b3a4c9e8a7b2c3d4e5f6b') }
# Verify data test> db.test.findOne()
{ _id: ObjectId('657b3a4c9e8a7b2c3d4e5f6b'), message: 'Hello from macOS!', chip: 'M2' }
# Exit test> exit
βœ… MongoDB is Running! If you can connect and run these commands, MongoDB is installed correctly and working perfectly on your Mac.
βš™οΈ

Configuration

Important file locations

File Locations (Homebrew)
Paths
# Configuration file (Apple Silicon) /opt/homebrew/etc/mongod.conf # Configuration file (Intel) /usr/local/etc/mongod.conf # Data directory (Apple Silicon) /opt/homebrew/var/mongodb # Data directory (Intel) /usr/local/var/mongodb # Log files (Apple Silicon) /opt/homebrew/var/log/mongodb # Log files (Intel) /usr/local/var/log/mongodb
Edit Configuration

Edit the configuration file to customize MongoDB settings:

Terminal
# Apple Silicon $ nano /opt/homebrew/etc/mongod.conf # Intel $ nano /usr/local/etc/mongod.conf
⚠️ After Configuration Changes Always restart MongoDB after editing the config file:
$ brew services restart mongodb-community
πŸ”§

Troubleshooting

Common macOS issues

MongoDB Won't Start

Check if port is in use:

$ lsof -i :27017

Check permissions:

# Apple Silicon $ sudo chown -R $(whoami) /opt/homebrew/var/mongodb # Intel $ sudo chown -R $(whoami) /usr/local/var/mongodb

View logs:

# Apple Silicon $ tail -f /opt/homebrew/var/log/mongodb/mongo.log # Intel $ tail -f /usr/local/var/log/mongodb/mongo.log
Command Not Found

If mongod or mongosh not found:

  1. Verify installation: brew list | grep mongodb
  2. Reinstall: brew reinstall mongodb-community
  3. Check PATH: echo $PATH
Apple Silicon Rosetta Issues

On M1/M2/M3 Macs, if you get architecture errors:

  1. Make sure you're using the ARM64 version, not x86_64
  2. Use native ARM Homebrew (/opt/homebrew)
  3. Reinstall: brew uninstall mongodb-community && brew install mongodb-community
πŸŽ‰ Installation Complete!

Congratulations! MongoDB is now running on your Mac. Here's what to do next:

  • Install MongoDB Compass: Get the GUI tool: brew install --cask mongodb-compass
  • Learn mongosh: Practice MongoDB shell commands
  • Create Your First Database: Start building applications
  • Set Up Authentication: Secure your MongoDB instance
  • Explore Atlas: Try MongoDB's cloud offering for production