How to install MongoDB?

MongoDB is available for both Cloud and Self managed platform.

MongoDB Atlas is the fully managed and automated cloud based database service available for AWS, Azure, and Google Cloud.

For self manage, MongoDB offers two editions, Community and Enterprise.

We will start with various editions of mongodb and then how to install them.

The MongDB Installation might require knowledge of servers and development on some operating systems.

MongoDB Editions

MongoDB comes with two editions, Community and Enterprise. Community is the open-source version with great feature, but Enterprise comes with advance features and support.

MongoDB Community Vs Enterprise

MongoDB Community Vs Enterprise
Community Enterprise
Price Free Paid
Role based Access Controls yes yes
Advance Support no Yes
Advance Security no yes
Advance Features no yes

Also install MongoDB Compass, a free GUI for MongoDB Compass.

Install MongoDB on MacOS

MongoDB is supported in MacOS 10.11 and above versions.

MongoDB 4.2 Community Editions supports only macOS 10.12 or later. We are installing MongoDB 4.2 in MacOS 10.14 (Mojave).

Install MongoDB using Homebrew.

Install Homebrew brew package manager for MacOS. By default MacOS doesn't include brew package. Here is step by step guide to install MongoDB using brew.

  1. brew tap mongodb/brew
  2. brew install mongodb-community@4.2

Run MongoDB Community edition


brew services start mongodb-community@4.2


brew services stop mongodb-community@4.2

Run MongoDb in background

mongod --config /usr/local/etc/mongod.conf --fork

Start MongoDb


Install MongoDB using .tgz Tarball

Here is the step by step guide to install MongoDB Community edition on MacOS using .tgz Tarball.

  1. Download MongoDB from official site, i.e. MongoDB 4.2 .tgz
  2. Extract files from archive. Double click on .tgz file. The extracted version would end with .tar.
  3. Copy binaries in /bin directory to usr/local/bin. Press Cmd + shift + g , and type /usr/local/bin/
  4. Create a directory to store MongoDB data.
    mkdir -p /data/db
  5. Check permissions of directory.
    sudo chown -R `id -un` /data/db
  6. Run MongoDB demon.
  7. In another terminal window, run Mongo shell.
  8. To exit mongo shell, type quit() and to stop MongoDB demon, press ctrl+c

Install MongoDB on windows

Here is a step by step guide to install MongoDb on windows. You need Windows 10 / 8.1 / 8 / 7 or Windows Server 2008 R2 / 2012 / 2012 R2 / 2016 / 2019.

  1. Download MongoDB MSI Installer.
  2. Run MongoDB MSi Installer.
  3. Follow installation steps.
  4. Choose MongoDB as windows services or just install binaries.
  5. Install MongoDB Compass.
  6. Create a directory data/db in C drive, or default drive of OS.
  7. Start MongoDB.

Install MongoDB on Linux

To install MongoDB on Linux, please check list of supported Linux Distributions.

Linux OS supporting MongoDB

  1. Red Hat
  2. Ununtu
  3. Debian
  4. SUSE

Install MongoDB on Ubuntu

  1. Import public key using package management.
    wget -qO - | sudo apt-key add -

    For error gnupg is not installed, try this

    sudo apt-get install gnupg
    wget -qO - | sudo apt-key add -
  2. echo "deb [ arch=amd64,arm64 ] bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
  3. Reload local package database
    sudo apt-get update
  4. Install MongoDBpackage
    sudo apt-get install -y mongodb-org
  5. Run MongoDB