Navigation

Install MongoDB Enterprise on macOS

Overview

Use this tutorial to install MongoDB Enterprise on macOS systems. MongoDB Enterprise is available on select platforms and contains support for several features related to security and monitoring.

Platform Support

MongoDB 3.6 is not tested on APFS, the new filesystem in macOS 10.13 and may encounter errors.

MongoDB only supports macOS versions 10.7 (Lion) and later on Intel x86-64. Versions of MongoDB Enterprise prior to 3.2 did not support macOS.

Note

Starting with MongoDB 3.6, MongoDB binaries, mongod and mongos, bind to localhost by default. From MongoDB versions 2.6 to 3.4, only the binaries from the official MongoDB RPM (Red Hat, CentOS, Fedora Linux, and derivatives) and DEB (Debian, Ubuntu, and derivatives) packages would bind to localhost by default. To learn more about this change, see Localhost Binding Compatibility Changes.

Install MongoDB Enterprise

1

Download the latest production release of MongoDB Enterprise from the MongoDB Download Center.

2

Extract the files from the downloaded archive.

For example, from a system shell, you can extract through the tar command:

tar -zxvf mongodb-osx-ssl-x86_64-enterprise-3.6.15.tgz

If your web browser automatically unzips the file as part of the download, the file would end in .tar instead.

3

Copy the extracted archive to the target directory.

Copy the extracted folder to the location from which MongoDB will run.

mkdir -p mongodb
cp -R -n mongodb-osx-ssl-x86_64-enterprise-3.6.15/ mongodb
4

Ensure the location of the binaries is in the PATH variable.

The MongoDB binaries are in the bin/ directory of the archive. To ensure that the binaries are in your PATH, you can modify your PATH.

For example, you can add the following line to your shell’s rc file (e.g. ~/.bashrc):

export PATH=<mongodb-install-directory>/bin:$PATH

Replace <mongodb-install-directory> with the path to the extracted MongoDB archive.

Run MongoDB Enterprise

1

Create the data directory.

Before you start MongoDB for the first time, you must create the directory 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 the MongoDB default data directory of /data/db. On macOS 10.15 Catalina, you must use a different data directory, such as /usr/local/var/mongodb.

2

Create the log directory.

You must also create the directory in which the mongod process will write its log file:

For example, to create the /usr/local/var/log/mongodb directory:

sudo mkdir -p /usr/local/var/log/mongodb
3

Set permissions for the data and log directories.

Ensure that the user account running mongod has read and write permissions for these two directories. If you are running mongod as your own user account, and you just created the two directories above, they should already accessible to your user. 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
4

Run MongoDB.

To run MongoDB, run the mongod process at the system prompt, 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 values for dbpath, logpath, fork, and many other parameters in a configuration file.

Run mongod with command-line parameters

Run the mongod process at the system prompt, providing the three necessary parameters directly on the command-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 a configuration file with the config parameter:

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

Note

If you receive an error message indicating that mongod could not be opened, go to System Preferences > Security and Privacy. Under the General tab, click the “Allow Anyway” button to the right of the message about mongod.

5

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 for any error messages.

6

Begin using MongoDB.

Start a mongo shell on the same host machine as the mongod. You can run the mongo shell without any command-line options to connect to a mongod that is running on your localhost with the default port of 27017:

mongo

Note

If you needed to explicitly approve the mongod application in System 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 running on a different host and/or port, see The mongo Shell.

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See Getting Started for the available editions.