Overview
Use this tutorial to install MongoDB 9.0 Enterprise Edition on macOS using the third-party Homebrew package manager.
Installing MongoDB through Homebrew also installs the MongoDB Database Tools. See Using the MongoDB Database Tools for more information.
Considerations
Platform Support
MongoDB 9.0 Enterprise Edition supports macOS 14 or later, and requires a Haswell or newer CPU architecture.
For more information, see Platform Support.
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Before You Begin
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.
Install Xcode Command-line Tools
Homebrew requires the Xcode command-line tools from Apple's Xcode.
To install the Xcode command-line tools, run the following command:
xcode-select --install
Install Homebrew
macOS does not include the Homebrew brew package by default.
To install Homebrew, use the official Homebrew installation instructions.
Install MongoDB Enterprise Edition
To install MongoDB Enterprise Edition using Homebrew, complete the following steps:
Add the MongoDB Homebrew tap.
The MongoDB Homebrew tap makes the official MongoDB and Database Tools Homebrew formulae available on your system.
To add the MongoDB Homebrew tap, run the following command:
brew tap mongodb/brew
Then, mark the tap as trusted:
brew trust mongodb/brew
If you have already done this for a previous installation of MongoDB, you can skip this step.
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.
Run MongoDB Enterprise Edition
Follow these steps to run MongoDB Enterprise 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.
Note
For macOS systems that have installed MongoDB using the Homebrew installation method, the open files limit might not be automatically set when starting MongoDB through brew services. You might need to manually configure the ulimit values.
See Ulimit Settings for more information.
To run
mongodmanually as a background process using a config file:If your deployment does not use TLS connections, use the
--forkoption: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 Apple Silicon processors:
To run
mongodmanually as a background process specifying--dbpathand--logpathon the command line, run:mongod --dbpath /path/to/dbdir --logpath /path/to/mongodb.log --fork To stop a
mongodrunning as a background process, connect to themongodusing mongosh, and issue theshutdowncommand 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 Settings
Click Privacy & Security in the sidebar.
In the Security section, click the Open Anyway button to the right of the message about
mongod.
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-enterpriselisted asstarted.If you started MongoDB manually as a background process:
ps aux | grep -v grep | grep mongod You should see your
mongodprocess 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.
Connect and Use MongoDB
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:
Additional Information
Localhost Binding by Default
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:
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.
Included Binaries
The installation includes the following binaries:
Note
The installation also includes the MongoDB Database Tools. See Using the MongoDB Database Tools for more information.
File Paths
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 | |
|---|---|---|
|
| |
|
| |
|
|
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