Navigation

Install MongoDB Community Edition on macOS

Overview

The following tutorial uses Homebrew to install MongoDB 4.2 Community Edition on macOS systems. To install a different version of MongoDB, please refer to that version’s documentation. For example:

Platform Support

MongoDB 4.2+ only supports macOS versions 10.12+ on Intel x86-64. See Supported Platforms for more information.

Install MongoDB Community Edition

Prerequisites

If you have the Homebrew brew package installed on your OSX host and you have previously tapped the official MongoDB Homebrew Tap, skip to the prerequisites and go to the Install MongoDB step.

Install Homebrew

OSX does not include the Homebrew brew package by default. Install brew using the official instructions.

Tap the MongoDB Homebrew Tap

Issue the following from the terminal to tap the official MongoDB Homebrew Tap:

brew tap mongodb/brew

Install MongoDB

From a terminal, issue the following:

brew install mongodb-community@4.2

Tip

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

In addition to the binaries, the install creates:

Run MongoDB

From a terminal, issue the following to run MongoDB (i.e. the mongod process) in the foreground.

mongod --config /usr/local/etc/mongod.conf

Alternatively, to run MongoDB as a macOS service, issue the following (the process uses the /usr/local/etc/mongod.conf file created during the install):

brew services start mongodb-community@4.2

Connect and Use MongoDB

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

mongo

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

Additional Considerations

Troubleshooting ChecksumMismatchError

If you have previously installed an older version of the formual, you may encounter a ChecksumMismatchError, as in the following example:

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@4.2
    

Localhost Binding

Starting with MongoDB 3.6, MongoDB binaries, mongod and mongos, bind to localhost by default.

When bound only to the localhost, these binaries can only accept connections from clients that are running on the same machine. Remote clients cannot connect to the binaries bound only to localhost. For more information, including how to override and bind to other ip addresses, see Localhost Binding Compatibility Changes.