Navigation

Install MongoDB Community Edition on macOS

Overview

The following tutorial uses brew to install MongoDB 3.6 Community Edition on macOS systems. To install a different version of MongoDB, please refer to that version’s documentation.

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.

Platform Support

Note

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.

See Supported Platforms for more information.

Install MongoDB Community Edition

Prerequisites

If you have the Homebrew brew package installed on your OSX host and you have previously tapped the official MongoDB Homebrew Tap, skip the prerequisites and go to the Install MongoDB step.

Install XCode

Apple’s XCode includes command-line tools that are required by brew, and is available for free on the App Store. Make sure you are running the latest version.

Install Homebrew

Issue the following from the terminal to tap the official MongoDB Homebrew Tap:

brew tap mongodb/brew

Install MongoDB

From a terminal, issue the following:

brew install mongodb-community@3.6

In addition to the binaries, the install creates:

Run MongoDB

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, issue the following:

    brew services start mongodb-community
    
  • To run MongoDB manually as a background process, issue the following:

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

Both methods use the /usr/local/etc/mongod.conf file created during the install. You can add your own MongoDB configuration options to this file as well.

To verify that MongoDB is running, search for mongod in 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 shell to the running instance. From a new terminal, issue the following:

mongo

For information on CRUD (Create,Read,Update,Delete) operations, see: