DEV Community


How To Install MongoDB Server On Windows & Linux

djnitehawk profile image Đĵ ΝιΓΞΗΛψΚ Updated on ・3 min read

Installation of MongoDB takes less than 5 minutes on both Windows and Linux. Here are the steps you need to take in order to be up and running as fast as possible.

Note: MongoDB is at version 4.2.2 as of writing this article. Please post a comment below if you'd like me to update the tutorial for the latest version.

On Linux

open up a terminal and issue the following commands to install the server. these commands are for a 64-bit ubuntu system. if you're linux flavor is different, please click here for instructions.

wget -qO - | sudo apt-key add -
echo "deb [ arch=amd64 ] bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
mkdir /mongodb
mkdir /mongodb/log
sudo chown -R mongodb:mongodb /mongodb
echo "" > /etc/mongod.conf
nano /etc/mongod.conf

then copy & paste the following into nano, save & exit.

  dbPath: /mongodb
  directoryPerDB: true
    enabled: true

  destination: file
  logAppend: true
  path:  /mongodb/log/mongod.log

  port: 27017

then enter the following in the terminal, which will show that mongodb server is active and running.

systemctl enable mongod.service
sudo service mongod start
sudo service mongod status

On Windows

first download the installer msi from this direct link and run it. do the following during installation:

  • choose the complete installation option
  • check the install mongodb as a service box
  • select run service as network service user
  • change data directory to: C:\DATA
  • change log directory to: C:\DATA\Log
  • uncheck the install mongodb compass box

note: the installer will try to start the mongodb service and fail sometimes. if that happens simply choose to ignore and finish the installation.

if starting the service did not fail, enter the following command in an administrator cmd window to stop the service before proceeding to the next step:

net stop mongodb

next, create a text file called mongod.cfg somewhere and paste the following in to it. save & close the file afterwards.

  dbPath: C:\DATA
  directoryPerDB: true
    enabled: true

  destination: file
  logAppend: true
  path:  C:\DATA\Log\mongod.log

  port: 27017

now, copy mongod.cfg file over to the following location replacing the existing file there: C:\Program Files\MongoDB\Server\4.2\bin

then open up an administrator cmd window and enter the following to start the mongodb service:

net start mongodb

next, add the above folder to the system path environment variable by running the following command in an administrator cmd window:

setx path /M "%path%";"%ProgramFiles%\MongoDB\Server\4.2\bin"

Test Your Installation

open up a terminal/ cmd window and enter the following command:


enter the following at the mongo shell prompt that comes up:

show dbs

it should give you an output similar to this:

admin   0.000GB
config  0.000GB
local   0.000GB

that's it for the installation and configuration of mongodb server. if you don't like dealing with the mongo shell, you can use a gui database manager. below is a list of such managers in order of personal preference:

  1. navicat for mongodb
  2. mongodb compass
  3. studio3t


Editor guide