There are two different ways for installing MongoDB on your Mac either manually or through Homebrew. We will be looking at the steps required to install MongoDB through Homebrew. If you don’t have brew already installed on your Mac, you can install it by simply running the below command on your Terminal.

Install brew

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Homebrew Installation

Update Homebrew’s package database

$ brew update

Update Brew

Install the MongoDB binaries

$ brew install mongodb

MongoDB installation

Build MongoDB from Source with TLS/SSL Support

$ brew install mongodb --with-openssl

Install the Latest Development Release of MongoDB

$ brew install mongodb --devel

Run MongoDB

1. Create db directory

$ sudo mkdir -p /data/db

2. To keep the MongoDB always running even after restarts use the below commands.

//Start mongod main process on session start:
$ ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
 
//Start MongoDB now, in background, and keep it running
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

3. Just type mongo on your Terminal and start using the MongoDB

$ mongo

run_mongo

Some of the command required to change the default configurations

//Select manually the data directory
$ mongod --dbpath 
 
//Select manually the log file
$ mongod --logpath 
 
//Select manually the configguration file
$ mongod --config