How to Install MongoDB in macOS
MongoDB Setup
Install Homebrew
- Visit: https://brew.sh/
- Run this command in terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Verify brew is installed by typing:
brew
Install MongoDB
- Visit: MongoDB Install Guide
Prerequisite
- Install Xcode (if not already):
xcode-select --install
Step-by-step Commands:
Tap MongoDB formula:
brew tap mongodb/brew
Update brew:
brew update
Install MongoDB:
brew install mongodb-community@8.0
Start MongoDB service (in a fresh terminal):
brew services start mongodb-community@8.0
Use MongoDB
Start Mongo Shell:
mongosh
Check databases:
show dbs
(Default databases will appear)
MongoDB Compass
- Download from: https://www.mongodb.com/products/tools/compass
- Move downloaded file to Applications
- Open MongoDB Compass
- Connect using localhost