Docs Menu
Docs Home
/
MongoDB Manual
/ / /

Install MongoDB Community Edition on macOS

On this page

  • Overview
  • Considerations
  • Install MongoDB Community Edition
  • Run MongoDB Community Edition
  • Using the MongoDB Database Tools
  • Additional Information

Use this tutorial to install MongoDB 8.0 Community Edition on macOS using the third-party Homebrew package manager.

Starting with MongoDB 4.4.1, installing MongoDB through Homebrew also installs the MongoDB Database Tools. See Using the MongoDB Database Tools for more information.

This tutorial installs MongoDB 8.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

MongoDB 8.0 Community Edition supports macOS 11 or later.

For more information, see Platform Support.

Before deploying MongoDB in a production environment, consider the Production Notes for Self-Managed Deployments document which offers performance considerations and configuration recommendations for production MongoDB deployments.

Ensure your system meets each of the following prerequisites. You only need to perform each prerequisite step once on your system. If you have already performed the prerequisite steps as part of an earlier MongoDB installation using Homebrew, you can skip to the installation procedure.

Homebrew requires the Xcode command-line tools from Apple's Xcode.

  • Install the Xcode command-line tools by running the following command in your macOS Terminal:

    xcode-select --install

macOS does not include the Homebrew brew package by default.

Follow these steps to install MongoDB Community Edition using Homebrew's brew package manager. Be sure that you have followed the installation prerequisites above before proceeding.

  1. Tap the MongoDB Homebrew Tap to download the official Homebrew formula for MongoDB and the Database Tools, by running the following command in your macOS Terminal:

    brew tap mongodb/brew

    If you have already done this for a previous installation of MongoDB, you can skip this step.

  2. To update Homebrew and all existing formulae:

    brew update
  3. To install MongoDB, run the following command in your macOS Terminal application:

    brew install mongodb-community@8.0

Tip

Alternatively, you can specify a previous version of MongoDB if desired. You can also maintain multiple versions of MongoDB side by side in this manner.

Tip

If you have previously installed an older version of the formula, you may encounter a ChecksumMismatchError. To resolve, see Troubleshooting ChecksumMismatchError.

The installation includes the following binaries:

In addition, the installation creates the following files and directories at the location specified below, depending on your Apple hardware:

Intel Processor
Apple Silicon Processor
/usr/local/etc/mongod.conf
/opt/homebrew/etc/mongod.conf
/usr/local/var/log/mongodb
/opt/homebrew/var/log/mongodb
/usr/local/var/mongodb
/opt/homebrew/var/mongodb

See Apple's documentation for the current list of Apple hardware using the Apple Silicon processor. You can also run the following command to check where brew has installed these files and directories:

brew --prefix

Starting with MongoDB 4.4.1, the installation also includes the MongoDB Database Tools. See Using the MongoDB Database Tools for more information.

Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.

You can run MongoDB as a macOS service using brew, or you can run MongoDB manually as a background process. It is recommended to run MongoDB as a macOS service, as doing so sets the correct system ulimit values automatically (see ulimit settings for more information).

  • To run MongoDB (i.e. the mongod process) as a macOS service, run:

    brew services start mongodb-community@8.0

    To stop a mongod running as a macOS service, use the following command as needed:

    brew services stop mongodb-community@8.0
  • To run mongod manually as a background process using a config file:

    • If your deployment does not use TLS connections, use the --fork option:

      • For macOS running on Intel processors, run:

        mongod --config /usr/local/etc/mongod.conf --fork
      • For macOS running on Apple Silicon processors, run:

        mongod --config /opt/homebrew/etc/mongod.conf --fork
      • If your deployment uses TLS connections, use GNU Screen.

        • For macOS running on Intel processors:

          1
          screen -S <name-of-screen>
          2
          mongod --config /usr/local/etc/mongod.conf
          3

          Detach from your screen by typing Ctrl+a, then clicking d.

          4
          screen -ls
        • For macOS running on Apple Silicon processors:

          1
          screen -S <name-of-screen>
          2
          mongod --config /opt/homebrew/etc/mongod.conf
          3

          Detach from your screen by typing Ctrl+a, then clicking d.

          4
          screen -ls
  • To run mongod manually as a background process specifying --dbpath and --logpath on the command line, run:

    mongod --dbpath /path/to/dbdir --logpath /path/to/mongodb.log --fork

    To stop a mongod running as a background process, connect to the mongod using mongosh, and issue the shutdown command as needed.

Both methods use the mongod.conf file created during the install. You can add your own MongoDB configuration options to this file as well.

Note

macOS Prevents mongod From Opening

macOS may prevent mongod from running after installation. If you receive a security error when starting mongod indicating that the developer could not be identified or verified, do the following to grant mongod access to run:

  • Open System Preferences

  • Select the Security and Privacy pane.

  • Under the General tab, click the button to the right of the message about mongod, labelled either Open Anyway or Allow Anyway depending on your version of macOS.

To verify that MongoDB is running, perform one of the following:

  • If you started MongoDB as a macOS service:

    brew services list

    You should see the service mongodb-community listed as started.

  • If you started MongoDB manually as a background process:

    ps aux | grep -v grep | grep mongod

    You should see your mongod process in the output.

You can also view the log file to see the current status of your mongod process: /usr/local/var/log/mongodb/mongo.log.

To begin using MongoDB, connect mongosh to the running instance. From a new terminal, issue the following:

mongosh

For information on CRUD (Create,Read,Update,Delete) operations, see:

Starting in MongoDB 4.4.1, installing MongoDB through brew also installs the MongoDB Database Tools.

The MongoDB Database Tools are a collection of command-line utilities for working with a MongoDB deployment, including data backup and import/export tools like mongoimport and mongodump as well as monitoring tools like mongotop.

Once you have installed the MongoDB Server in the steps above, the Database Tools are available directly from the command line in your macOS Terminal application. For example you could run mongotop against your running MongoDB instance by invoking it in your macOS Terminal like so:

mongotop

It should start up, connect to your running mongod, and start reporting usage statistics.

See the MongoDB Database Tools Documentation for usage information for each of the Database Tools.

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

This value can be configured either:

  • in the MongoDB configuration file with bindIp, or

  • via the command-line argument --bind_ip

Warning

Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.

For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.

If you have previously installed an older version of the formula, you may encounter a ChecksumMismatchError resembling the following:

Error: An exception occurred within a child process:
ChecksumMismatchError: SHA256 mismatch
Expected: c7214ee7bda3cf9566e8776a8978706d9827c1b09017e17b66a5a4e0c0731e1f
Actual: 6aa2e0c348e8abeec7931dced1f85d4bb161ef209c6af317fe530ea11bbac8f0
Archive: /Users/kay/Library/Caches/Homebrew/downloads/a6696157a9852f392ec6323b4bb697b86312f0c345d390111bd51bb1cbd7e219--mongodb-macos-x86_64-4.2.0.tgz
To retry an incomplete download, remove the file above.

To fix:

  1. Remove the downloaded .tgz archive.

  2. Retap the formula.

    brew untap mongodb/brew && brew tap mongodb/brew
  3. Retry the install.

    brew install mongodb-community@8.0

Back

Install using .tgz Tarball