Install MongoDB Enterprise on macOS
Overview
Use this tutorial to install MongoDB Enterprise on macOS systems. MongoDB Enterpriseis available on select platforms and contains support for several featuresrelated to security and monitoring.
Platform Support
- MongoDB 4.0 may lose data during unclean shutdowns on macOS 10.12.x and 10.13.x.
For details, see WT-4018.
- MongoDB 4.2+ only supports macOS versions 10.12 and later on Intel x86-64.
Note
Starting with MongoDB 3.6, MongoDB binaries, mongod
andmongos
, bind to localhost
by default.From MongoDB versions 2.6 to 3.4, only the binaries from theofficial MongoDB RPM (Red Hat, CentOS, Fedora Linux, and derivatives)and DEB (Debian, Ubuntu, and derivatives) packages would bind tolocalhost
by default. To learn more about this change, seeLocalhost Binding Compatibility Changes.
Install MongoDB Enterprise
Download the MongoDB tarball.
Download the latest production release of MongoDB Enterprise fromthe MongoDB Download Center.
Extract the files from the downloaded archive.
- tar -zxvf mongodb-macos-x86_64-enterprise-4.2.1.tgz
If your web browser automatically unzips the file as part of thedownload, the file would end in .tar
instead.
Ensure the binaries are in a directory listed in your PATH environment variable.
The MongoDB binaries are in the bin/
directory of the tarball.You can either:
- Copy the binaries into a directory listed in your
PATH
variable, such as/usr/local/bin
(Update/path/to/the/mongodb-directory/
with your installationdirectory as appropriate)
- sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/
- Create symbolic links to the binaries from a directory listed inyour
PATH
variable, such as/usr/local/bin
(Update/path/to/the/mongodb-directory/
with your installationdirectory as appropriate):
- sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
Run MongoDB Enterprise
Create the data directory.
Before you start MongoDB for the first time, you must create thedirectory to which the mongod
process will write data.
For example, to create the /usr/local/var/mongodb
directory:
- sudo mkdir -p /usr/local/var/mongodb
Important
Starting with macOS 10.15 Catalina, Apple restricts access to theMongoDB default data directory of /data/db
. On macOS 10.15Catalina, you must use a different data directory, such as/usr/local/var/mongodb
.
Create the log directory.
You must also create the directory in which the mongod
processwill write its log file:
For example, to create the /usr/local/var/log/mongodb
directory:
- sudo mkdir -p /usr/local/var/log/mongodb
Set permissions for the data and log directories.
Ensure that the user account running mongod
has readand write permissions for these two directories. If you are runningmongod
as your own user account, and you just createdthe two directories above, they should already accessible to youruser. Otherwise, you can use chown
to set ownership,substituting the appropriate user:
- sudo chown my_mongodb_user /usr/local/var/mongodb
- sudo chown my_mongodb_user /usr/local/var/log/mongodb
Run MongoDB.
To run MongoDB, run the mongod
process at the systemprompt, providing the two parameters dbpath
and logpath
from above, and the fork
parameter to run mongod
in the background. Alternatively, you may choose to store the valuesfor dbpath
, logpath
, fork
, and many other parameters in aconfiguration file.
Run mongod with command-line parameters
Run the mongod
process at the system prompt,providing the three necessary parameters directly on thecommand-line:
- mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
Run mongod with a configuration file
Run the mongod
process at the system prompt,providing the path to aconfiguration filewith the config
parameter:
- mongod --config /usr/local/etc/mongod.conf
Note
If you receive an error message indicating that mongod
couldnot be opened, go to System Preferences > Security and Privacy.Under the General tab, click the “Allow Anyway” button to theright of the message about mongod.
Verify that MongoDB has started successfully.
Verify that MongoDB has started successfully:
- ps aux | grep -v grep | grep mongod
If you do not see a mongod
process running, check the logfile forany error messages.
Begin using MongoDB.
Start a mongo
shell on the same host machine as themongod
. You can run the mongo
shellwithout any command-line options to connect to amongod
that is running on your localhost with thedefault port of 27017:
- mongo
Note
If you needed to explicitly approve the mongod
application inSystem Preferences above, you must also do so for mongo
.
For more information on connecting using the mongo
shell, such as to connect to a mongod
instance runningon a different host and/or port, see The mongo Shell.
To help you start using MongoDB, MongoDB provides GettingStarted Guides in various driver editions. SeeGetting Started for the available editions.