Big Data and Hadoop (170 Blogs) Become a Certified Professional
AWS Global Infrastructure

Big Data

Topics Covered
  • Big Data and Hadoop (146 Blogs)
  • Hadoop Administration (8 Blogs)
  • Apache Storm (4 Blogs)
  • Apache Spark and Scala (29 Blogs)
SEE MORE

How To Install MongoDB on Mac Operating System?

Last updated on Apr 28,2020 24.8K Views

How To Install MongoDB on Mac Operating System?

In our previous article we talked about how you can install MongoDB architecture on your Windows operating system. In this article we will talk about how you can install MongoDB on Mac Operating systems.

Following pointers will be covered in this article,

  1. Pre-Requisites
  2. Installing and Running MongoDB via Homebrew
  3. Install MongoDB on Mac by Downloading it Manually

Let’s begin!

Install MongoDB on Mac

So what are the Pre-Requistes to install MongoDB on Mac,

Prerequisites

Before we can move ahead and teach you how to install MongoDB on the Mac operating system, make sure:

  1. That you are familiar with the Mac terminal as well as most of its commands as we will be making extensive use of both in the entirety of this article. 
  2. In this article we will talk about two methods by which you install the MongoDB platform on your Mac. One of the methods requires the installation of Homebrew.
  3. Homebrew is a package installation manager for the Mac operating system. It has been specifically designed to ease the process of installing open source software like MongoDB on your Mac. In the homebrew ecosystem you can simply type, brew install MongoDB and the same will be installed onto your system.

As mentioned in an earlier paragraph, there are two main ways of installing the MongoDB software onto your Mac. The easiest one of the two is to make use of the Homebrew package installation manager and the second is to download the MongoDB package from https://www.mongodb.org/downloads#production and install it via the Mac terminal. 

Output - Install MongoDB On Windows - Edureka

Moving on let us see how to install MongoDB on Mac and then run it with Homebrew,

Installing and Running MongoDB via Homebrew

Let us start by explaining the easiest method to install MongoDB on your Mac. In order to do this, follow the steps outlined below. 

  1. Open the terminal app on your Mac and type in the command, brew update.
  2. Once the Homebrew platform has been updated, open Homebrew and type in the following command, brew install MongoDB.
  3. Once Mongo has been downloaded onto your Mac, create the default directory db. This is the default location, where all of your files, processes and collections created on the MongoDB platform will be stored. In order to do this, type in the following command: mkdir -p /data/db
  4. After you have finished the above step, you need to make sure that the /data/db has all the correct permissions in order for it to run on your system smoothly. In order to do this, type in the following command.
> sudo chown -R `id -un` /data/db
> # Enter your password
  1. Again open the terminal application on your Mac and type in the command, mongod. This will start the MongoDb server and thus start MongoDb on your system.
  2. Once the Mongo server is up and running, open another terminal window and type in the command, mongo. This will start the Mongo Shell and this will give you application access to the data you create on the MongoDb platform.
  3. Once all the above steps are completed, and you are done with using MongoDb on your Mac, you can type the command, quit() to quit the Mongo Shell.
  4. After this, press ctrl-c on your Mac keyboard to stop the MongoDb daemon.

Last but not the least we install MongoDB on Mac by downloading it manually,

Install MongoDb on Mac by Downloading it Manually

If you want to manually download the MongoDb package and install it on your Mac, then follow the steps outlined below. 

  1. Visit the following website and download the latest MongoDb version for your Mac: https://www.mongodb.org/downloads#production
  2. Once the download is complete, locate the downloaded gzipped tar file on your Mac and move it to the destination where you want MongoDb to be installed. In our case, we want the MongoDb to be installed at your Home Folder and thus the command for executing the same will look like this.
> cd Downloads
> mv mongodb-osx-x86_64-3.0.7.tgz ~/
  1. Once the above step is done, you need to extract the downloaded archive and change its name to something else which helps in portability as well as palatability. In our case, we named the file: > cd ~/ > tar -zxvf mongodb-osx-x86_64-3.0.7.tgz > mv mongodb-osx-x86_64-3.0.7 mongodb
  2. After this is done, you need to create the directory where you would like all the MongoDb files to be stored by default. You can either create the directory in the default location, that is mkdir -p /data/db or any directory of your choice depending on your needs. 
  3. Once created, you need to make sure that all your directories have the required permission. In order to check this, you can use the following code. 
> sudo chown -R `id -un` /data/db
> # Enter your password
  1. Once you are assured that your MongoDb directory has all the required permissions, open the terminal application on your Mac and type the command, ~/mongodb/bin/mongod to start the Mongo Server.
  2. In another terminal window, type the command ~/mongodb/bin/mongo in order to start the Mongo Shell. 
  3. Once you are done using Mongo on your Mac, type quit() on the terminal application to quit the platform. Additionally use the control plus c keys on your keyboard to stop the Mongo daemon in the background.

This brings us to the end of this article. I believe by now you know how to install MongoDB on Mac

Now that you have understood what is Big Data, check out the Big Data training by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe. The Edureka Big Data Hadoop Certification Training course helps learners become expert in HDFS, Yarn, MapReduce, Pig, Hive, HBase, Oozie, Flume and Sqoop using real-time use cases on Retail, Social Media, Aviation, Tourism, Finance domain.

Got a question for us? Mention them in the comments section and we will get back to you.

Upcoming Batches For Big Data Hadoop Certification Training Course
Course NameDateDetails
Big Data Hadoop Certification Training Course

Class Starts on 23rd March,2024

23rd March

SAT&SUN (Weekend Batch)
View Details
Comments
0 Comments

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

How To Install MongoDB on Mac Operating System?

edureka.co