- Install MongoDB >
- Install MongoDB Community Edition >
- Install MongoDB Community Edition on macOS
Install MongoDB Community Edition on macOS¶
On this page
Important
MongoDB 5.3 binaries are currently available only as release candidates. Release candidates can be used for early testing of new features, but are not suitable for production deployments.
This version of the manual is for an upcoming release and is currently a work in progress.
Overview¶
Use this tutorial to install MongoDB 5.0 Community Edition on macOS using the third-party Homebrew package manager.
Starting with MongoDB 4.4.1, installing MongoDB via Homebrew also installs the :dbtools:`MongoDB Database Tools </>`. See Using the MongoDB Database Tools for more information.
MongoDB Version¶
This tutorial installs MongoDB 5.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.
Considerations¶
Platform Support¶
Note
EOL Notice
- MongoDB 5.0 Community Edition removes support for macOS 10.13
MongoDB 5.0 Community Edition supports macOS 10.14 or later.
See prod-notes-supported-platforms for more information.
Production Notes¶
Before deploying MongoDB in a production environment, consider the Production Notes document which offers performance considerations and configuration recommendations for production MongoDB deployments.
Install MongoDB Community Edition¶
Prerequisites¶
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.
Install the Xcode command-line tools by running the following command in your macOS Terminal:
Install Homebrew¶
macOS does not include the Homebrew brew
package by default.
- Install
brew
using the official Homebrew installation instructions.
Installing MongoDB 5.0 Community Edition¶
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.
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:
If you have already done this for a previous installation of MongoDB, you can skip this step.
To update Homebrew and all existing formulae:
To install MongoDB, run the following command in your macOS Terminal application:
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:
- The
mongod
server - The
mongos
sharded cluster query router - The MongoDB Shell,
mongosh
In addition, the installation creates the following files and directories at the location specified below, depending on your Apple hardware:
Intel Processor | Apple M1 Processor | |
---|---|---|
configuration file | /usr/local/etc/mongod.conf |
/opt/homebrew/etc/mongod.conf |
log directory |
/usr/local/var/log/mongodb |
/opt/homebrew/var/log/mongodb |
data directory |
/usr/local/var/mongodb |
/opt/homebrew/var/mongodb |
See Apple’s documentation
for the current list of Apple hardware using the M1 processor. You can
also run the following command to check where brew
has installed
these files and directories:
Starting with MongoDB 4.4.1, the installation also includes the :dbtools:`MongoDB Database Tools </>`. See Using the MongoDB Database Tools for more information.
Run MongoDB Community Edition¶
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:To stop a
mongod
running as a macOS service, use the following command as needed:To run MongoDB (i.e. the
mongod
process) manually as a background process, run:For macOS running Intel processors:
For macOS running on Apple M1 processors:
To stop a
mongod
running as a background process, connect to themongod
using mongosh, and issue theshutdown
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:
You should see the service
mongodb-community
listed asstarted
.If you started MongoDB manually as a background process:
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
.
Connect and Use MongoDB¶
To begin using MongoDB, connect mongosh
to the
running instance. From a new terminal, issue the following:
Note
macOS Prevents mongosh
From Opening
macOS may prevent mongosh
from running after installation. If
you receive a security error when starting mongosh
indicating that the developer could not be identified or verified,
do the following to grant mongosh
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
mongosh
, labelled either Open Anyway or Allow Anyway depending on your version of macOS.
For information on CRUD (Create,Read,Update,Delete) operations, see:
Using the MongoDB Database Tools¶
Starting in MongoDB 4.4.1, installing MongoDB via brew
also installs
the MongoDB Database Tools.
The :dbtools:`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:
It should start up, connect to your running mongod
, and start
reporting usage statistics.
See the :dbtools:`MongoDB Database Tools Documentation</>` for usage information for each of the Database Tools.
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 binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp
, see
IP Binding.
Troubleshooting ChecksumMismatchError¶
If you have previously installed an older version of the formula,
you may encounter a ChecksumMismatchError
resembling the following:
To fix:
Remove the downloaded
.tgz
archive.Retap the formula.
Retry the install.