If you're developing applications that require a flexible, document-based database, MongoDB is a popular choice. In this guide, you'll learn how to install MongoDB on macOS using Homebrew, the easiest and most recommended method.
Prerequisites
Before you begin, make sure:
You're using macOS 10.14 (Mojave) or newer
You have Homebrew installed
(If not, install it by running):
Step 1: Tap the MongoDB Formula
MongoDB is no longer available directly from the core Homebrew repository, so you need to add the MongoDB tap:
Step 2: Install MongoDB Community Edition
Now install MongoDB:
Replace 7.0
with the latest version if needed.
Step 3: Start the MongoDB Service
To run MongoDB as a macOS service:
This will automatically start MongoDB every time your system boots.
To run it manually instead:
Step 4: Verify the Installation
Once the service is running, you can test your MongoDB installation:
This opens the MongoDB shell where you can start issuing commands, like:
Step 5: Stop MongoDB (Optional)
To stop the service:
Troubleshooting Tips
If
mongosh
isn't found, ensure/opt/homebrew/bin
is in yourPATH
.Check MongoDB logs at
/opt/homebrew/var/log/mongodb/mongo.log
if something fails to start.
Final Thoughts
With MongoDB installed, you're now ready to build and run modern web applications using its powerful NoSQL features. If you're using Node.js, Python, or any other backend, you can now integrate MongoDB and start developing!