Install MongoDB on Mac OS – Step by Step

0
43

How to install MongoDB on MacOS. In some projects, you need to use Mongo Database, you need to install MongoDB on Mac.

There are 2 ways to install MongoDB: Manual and Brew. I recommend you install it manually. I have 5 steps for this problem.

Step 1: Download .tar.gz MongoDB file

Go to MongoDB Download Center and Download it.

https://www.mongodb.com/download-center/community

Step 2: Extract downloaded file

tar -zxvf mongodb-osx-ssl-x86_64-4.0.5.tgz
Install MongoDB on MacOS - Extract file
Extract file

Step 3: Setup directory – Install MongoDB on MacOS

Move mongodb-osx-x86_64-4.0.5 directory to /usr/local/mongodb.

sudo mv mongodb-osx-x86_64-4.0.5 /usr/local/mongodb

Create the data directory.

sudo mkdir -p /data/db

The mongod process will use this to write data. So, you need to set permission for the data directory. Here is example:

sudo chown khanhnguyen /data/db
Install MongoDB on MacOS - Setup MongoDB directory
Install MongoDB on MacOS – Setup MongoDB directory

Step 4: Export MongoDB PATH

Open .bash_profile

open ~/.bash_profile # Open .bash_profile

And add the following exports.

# add MongoDB ~/.bash_profile
export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin

Reload bash_profile

source ~/.bash_profile

Step 5: Run MongoDB

First, you need run mongod process.

mongod

And now you can run mongo to use MongoDB in terminal

mongo

Read more MacOS Tip: Install Ubuntu on MacOS using VMware. Thank you.

REVIEW OVERVIEW
Install MongoDB on MacOS - Step by Step
SHARE
Previous articleHandle Missing Data in datasets
Next articleWhat is NLP?
A software engineer. Like sharing knowledge myself.

Leave a Reply

avatar