Installation of MongoDB on MacOS (original) (raw)

Last Updated : 5 May, 2026

MongoDB is a popular open-source NoSQL database designed for flexibility, scalability, and high performance. It is widely adopted for modern applications that require handling large volumes of real-time data efficiently.

System Requirements for Installing MongoDB on MacOS

Before installing MongoDB, ensure the system meets the following requirements:

Install MongoDB on MacOS Using .tgz tarball

To install MongoDB on MacOS, first download the MongoDB and then setup the command line. Follow these step-by-step instructions to install MongoDB on our macOS system using the .tgz tarball file.

Step 1:Download MongoDB

1. Go to MongoDB Download Center to download the MongoDB Community Server.

download mongodb

2. Here, We can select any version, OS, and package according to our requirement. For macOS we need to choose:

3. After selecting the appropriate version and settings, click on Download. Once the download is complete, you will have a .tgz file on your machine

1. Open Terminal and navigate to the folder where the .tgz file is located.

2. Extract the file with the following command

tar -xvzf mongodb-macos-x86_64-.tgz

extract .tgz file

3. The bin folder contains important executables:

Step 3: Setting Command Line Interface (mongo Shell)

To run MongoDB Shell, set the environment path using a profile file.

1. Use .bash_profile (macOS Mojave or earlier) or .zprofile (Catalina or later).

2. Create the file if it doesn’t exist in the home directory.

**Terminal commands:

**Note: Hidden files can be viewed in Finder using Command + Shift + .

After creating or getting .bash_profile or .zprofile set your path. Like, as shown in the below image:

newimagee

Here, /Users/anki/mongodb-macos-x86_64-4.2.2/bin points to the MongoDB binaries, while :$PATH ensures existing commands remain accessible. After updating .bash_profile or .zprofile, save the file and reload it using source so the terminal recognizes the new path.

369

**Note: For Catalina users when you run mongo or mongo --nodb command in your terminal, your macOS would not allow to run mongo. So, to run mongo you need to give them permission manually i.e,

System Preferences > Security & Privacy > Allow Anyway

Same procedure to run mongod

After setting up the MongoDB Shell, connection attempts may fail because the MongoDB server (mongod) is not running. To use the shell, the mongod service must be started locally on the system.

newimageeee

Step 4:Create a Data Directory for MongoDB

Before running mongod first we will create a folder or directory which will store all the data processed by the mongod.

1. Before running MongoDB, you need to create a directory to store MongoDB’s data.

2. Create the data directory using the following command:

mkdir -p ~/data/db

This directory will store the MongoDB data during its operation.

Step 5:Run the MongoDB Server (mongod)

Now we are going to run mongod with its data directory path. Here, mongod is the database server provided by the MongoDB. To start mongod you can use one of the following commands:

mongod --dbpath /data/db

sudo mongod --dbpath /data/db

sudo command

Here, sudo mongod --dbpath ~/MongoDB command to start mongod server and ~/MongoDB is data directory.

Step 6: Connect to MongoDB Using the Mongo Shell

Now we are going to connect our server (mongod) with mongo shell. So, keep that mongod terminal window and open a new terminal window and write mongo and now our mongo shell will successfully connect to the mongod.

**NOTE:

connecti mongod and mongo shell

Now, we are ready to write queries in the mongo Shell.