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 5.0.0 as of writing this article. Please post a comment below if you'd like me to update the tutorial for the latest version.
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 - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.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.
storage: dbPath: /mongodb directoryPerDB: true journal: enabled: true systemLog: destination: file logAppend: true path: /mongodb/log/mongod.log net: port: 27017 bindIp: 127.0.0.1
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
first download the installer msi from this direct link and run it. do the following during installation:
- choose the
- check the install mongodb as a service box
- select run service as
- change data directory to:
- change log directory to:
- 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.
storage: dbPath: C:\MongoDB\Data directoryPerDB: true journal: enabled: true systemLog: destination: file logAppend: true path: C:\MongoDB\Log\mongod.log net: port: 27017 bindIp: 127.0.0.1
mongod.cfg file over to the following location replacing the existing file there:
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\5.0\bin" exit
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:
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:
Top comments (0)