# Install MongoDB Community Edition on macOS
# Overview
Use this tutorial to install MongoDB 4.2 Community Edition on macOS using the third-party brew package manager.
# MongoDB Version
This tutorial installs MongoDB 4.2 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.
# Install MongoDB Community Edition
brew tap mongodb/brew
brew install mongodb-community@4.2
In addition to the binaries (opens new window), the install creates:
- the configuration file (opens new window) (
/usr/local/etc/mongod.conf) - the
log directory path(opens new window) (/usr/local/var/log/mongodb) - the
data directory path(opens new window) (/usr/local/var/mongodb)
# Run MongoDB Community Edition
To run MongoDB (i.e. the
mongod(opens new window) process) as a macOS service, issue the following:brew services start mongodb-community@4.2To stop a
mongod(opens new window) running as a macOS service, use the following command as needed:brew services stop mongodb-community@4.2To run MongoDB (i.e. the
mongod(opens new window) process) manually as a background process, issue the following:mongod --config /usr/local/etc/mongod.conf --forkTo stop a
mongod(opens new window) running as a background process, connect to themongod(opens new window) from the mongo shell, and issue theshutdown(opens new window) command as needed.db.shutdownServer();To verify that MongoDB is running, search for
mongodin your running processes:
ps aux | grep -v grep | grep mongod
You can also view the log file to see the current status of your mongod process: /usr/local/var/log/mongodb/mongo.log.
# Connect and Use MongoDB
To begin using MongoDB, connect a mongo (opens new window) shell to the running instance. From a new terminal, issue the following:
mongo
# Additional Information
# Troubleshooting ChecksumMismatchError
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:
Remove the downloaded
.tgzarchive.Retap the formula.
brew untap mongodb/brew && brew tap mongodb/brew
- Retry the install.
brew install mongodb-community@4.2