Installation guide for MongoDB (macOS)

Susmit Sircar
3 min readMay 19, 2018

MongoDB is a free and open-source document based database with the scalability and flexibility that you want with the querying and indexing that you need. I’ve been using this no-sql database for over the last 2 years and I am awestruck with the features it offers us:

  • Stores data in flexible, JSON-like documents.
  • Easily maps to the objects in your application code.
  • A distributed database at its core, so high availability, horizontal scaling, and geographic distribution.
  • Most importantly it’s free and open source and makes developers life easy with support to over 10+ languages.

In this blog I’ll help you to install MongoDB in your macOS in the most simplest way. I will be dividing the entire installation in 4 sections for anyone to understand it easily.

  1. Section 1:
Mongo DB Community Server Installation
  • Now let’s open the terminal and navigate to the downloads folder from the terminal — cd Downloads/
  • Unzip the zar file which we’ve installed in the downloads folder — tar xzf mongodb-osx-x86_64–x.x.x.tgz (x is the version number)
  • List the files in the folder — ls, and you’ll find a file named mongodb-osx-x86_64–x.x.x
  • Move the unzipped file to usr/local/mongodbsudo mv mongodb-osx-x86_64–x.x.x /usr/local/mongodb (It will prompt for your user name and password of your system)

2. Section 2:

  • We move towards the creation of mongoDB directory. Again lets move back to the terminal and type in — sudo mkdir -p /data/db (It will prompt for your user name and password of your system)
  • Type in — sudo chown sircarsmac/data/db (sircarsmac is my Mac name & the chown command changes ownership of files and directories in a Linux filesystem. To know your mac name you can type in — whoami in the terminal)

3. Section 3:

  • We are almost ready to go, except for setting the MongoDB path, so that we can directly run the mongo instance and the console from the terminal itself.
  • Type in — $cd (you’ll be redireted to the root directory of your system).
  • Type in open .bash_profile (If not created then type in $ touch .bash_profile).
  • Paste this lines: export MONGO_PATH=/usr/local/mongodb and export PATH=$PATH:$MONGO_PATH/bin and save the file.
export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin
  • Bingo we are done!!

4. Section 4:

  • Now for the final phase we’ ll check whether eveything has been installed in a proper way.
  • Open 2 terminals in one of them type in — mongod (It will start the mongo instance)
  • In the other type in mongo and hit enter, mongo console starts up (by default the port is 27017)
Starting mongo instance
Mongo terminal to execute query

Thank’s a lot for reading! If you have any questions or improvements — write a comment! I would love to hear from you!

--

--