MongoDB Installation
Written By: Avinash Malhotra
Updated on
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. Free Atlas database is available for 512mb to 5gb of storage using shared cluster.
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
Community | Enterprise | |
---|---|---|
Price | Free | Paid |
Role based Access Controls | Yes | Yes |
In Memory Storage Engine | No | Yes |
Encrypted Storage Engine | No | Yes |
Advance Support | No | Yes |
Advance Security | No | Yes |
Latest Features | No | Yes |
MongoDB Compass
Also install MongoDB Compass, a free GUI for MongoDB. It can handle both in premises and cloud databases. We can check, update, delate and take backup, upload bulk data using 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.
- brew tap mongodb/brew
- brew install mongodb-community@4.2
Run MongoDB Community edition
Run
Stop
Run MongoDb in background
Start MongoDb
Install MongoDB using .tgz Tarball
Here is the step by step guide to install MongoDB Community edition on MacOS using .tgz Tarball.
- Download MongoDB from official site, i.e. MongoDB 4.2 .tgz
- Extract files from archive. Double click on .tgz file. The extracted version would end with
.tar
. - Copy binaries in /bin directory to usr/local/bin. Press Cmd + shift + g , and type /usr/local/bin/
- Create a directory to store MongoDB data.
mkdir -p /data/db
- Check permissions of directory.
sudo chown -R `id -un` /data/db
- Run MongoDB demon.
~/mongodb/bin/mongod
- In another terminal window, run Mongo shell.
~/mongodb/bin/mongo
- To exit mongo shell, type quit() and to stop MongoDB demon, press ctrl+c
For MacOS Catalina and above
With MacOS Catalina update, Apple secure their file system. That's the reason MongoDB will not start in MacOS Catalina and above MacOS like MacOS Big Sur etc.
To start MongoDB in Catalina, we need to change default directory path of MongoDB. Use following steps to do this.
- Open Terminal window.
- Create a new directory in user.
- Type
sudo mongod --dbpath ~/MongoDB
- Type
mongo
to run MongoDB.
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.
- Download MongoDB MSI Installer.
- Run MongoDB MSi Installer.
- Follow installation steps.
- Choose MongoDB as windows services or just install binaries.
- Install MongoDB Compass.
- Create a directory data/db in C drive, or default drive of OS.
- Start MongoDB.
To start mongodb server in windows os, we have to type mongod
in cmd. Some times this command will not work, so we have to setup environment variables.
Setup Environments Variables
- Right click on My Computer and choose Properties
- Click Advanced System setting in left
- For windows 10 and 11, Goto Control panel and click System and Security and then System and then choose Advanced system setting on right menu and then choose Environment Variables at bottom.
- Choose Path in System variables and click edit.
- Copy the path of bin in new line and then press ok.
- Close all windows and run mongod in cmd
Install MongoDB on Linux
To install MongoDB on Linux, please check list of supported Linux Distributions.
Linux OS supporting MongoDB
- Red Hat
- Ununtu
- Debian
- SUSE
- AMAZON
Install MongoDB on Ubuntu
-
Import public key using package management.
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
For error
gnupg is not installed
, try thissudo apt-get install gnupgwget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add - -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
- Reload local package database
sudo apt-get update
- Install MongoDBpackage
sudo apt-get install -y mongodb-org
- Run MongoDB