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):

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

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:

brew tap mongodb/brew

Step 2: Install MongoDB Community Edition

Now install MongoDB:

brew install mongodb-community@7.0

Replace 7.0 with the latest version if needed.

Step 3: Start the MongoDB Service

To run MongoDB as a macOS service:

brew services start mongodb/brew/mongodb-community

This will automatically start MongoDB every time your system boots.

To run it manually instead:

mongod --config /opt/homebrew/etc/mongod.conf

Step 4: Verify the Installation

Once the service is running, you can test your MongoDB installation:

mongosh

This opens the MongoDB shell where you can start issuing commands, like:

show dbs

Step 5: Stop MongoDB (Optional)

To stop the service:

brew services stop mongodb/brew/mongodb-community

Troubleshooting Tips

  • If mongosh isn't found, ensure /opt/homebrew/bin is in your PATH.

  • 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!