Digital Communication


Digital Communication

Install MongoDB on Debian: explanation


The MongoDB document-oriented database management system is very popular, especially because it can be installed in just a few steps under Linux distributions like Debian 10. The whole process of installing MongoDB on Debian should be done in the terminal.

Installing MongoDB on Debian: What You Need

To install MongoDB on Debian 10, you do not need much: in principle, it is enough to know the basic commands of the Linux terminal. However, you need a current Debian release. In this article, we introduce you to the installation process from Debian version 10. It is also necessary that the operating system of the device used is 64-bit. Otherwise, the NoSQL database installation will not work.


MongoDB can not only be installed on Debian, but also on all the others linux distros. However, if you want to install MongoDB on Ubuntu for example, the process will be slightly different.

Install MongoDB on Debian: Step by Step Guide

Step 1: Download the MongoDB key

You must first import MongoDB GPG public key. Because you may not have installed the necessary program for this yet, first check whether the software GnuPG already works on your system. To do this, you can use the following command:

dpkg --get-selections gnupg

If you cannot find the GnuPG software on your system, then install from terminal by inserting the line of code below. Otherwise, you can skip this step.

sudo apt-get install gnupg

You can then get the MongoDB public key by entering the following command:

wget -qO - | sudo apt-key add -

Step 2: Create a list file

The next step is to create a adapted list file to your version of Debian. For this too you can simply use the terminal:

echo "deb buster/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

To have the MongoDB repository added to your system, you must then update your computer. This process may take a few moments depending on the number of updates to be performed. The following command starts the updates:

Step 3: Install MongoDB Packages

Now begins the actual installation of MongoDB. The command to use to install MongoDB however differs between system versions. In general, it is sufficient to install the latest version of MongoDB.

sudo apt-get install -y mongodb-org


Be sure to install the package called “mongodb-org”. It’s about official package of the database management system. However, the “mongodb” package included in Debian cannot be installed by following these instructions.

If you want to install a specific version of MongoDB, the installation command will be different in that you have to choose this same version number for each package. So, if you want to install MongoDB version 6.0.1 on your system, you can use the following command:

sudo apt-get install -y mongodb-org=6.0.1 mongodb-org-database=6.0.1 mongodb-org-server=6.0.1 mongodb-mongosh=6.0.1 mongodb-org-mongos=6.0.1 mongodb-org-tools=6.0.1

The installation process may take a few moments. Once done, you have officially installed MongoDB on Debian.

Start MongoDB

To start MongoDB, you can use the following command:

sudo systemctl start mongod

If an error message appears, then try running the following command to reload your system’s configuration files and units :

sudo systemctl daemon-reload

Stop or restart MongoDB

I’stop MongoDB is also done using a simple terminal command:

sudo systemctl stop mongod

The situation is similar in the case of reboot :

sudo systemctl restart mongod

To check if the command you ran did not impact theMongoDB status (MongoDB status), you can use the following command:

sudo systemctl status mongod

Add password to MongoDB

MongoDB’s default settings do not include no password protection. If you wish, however, you can add one very easily.

Access to the configuration file

First, you must open MongoDB configuration file :

Web hosting with personal advisor!

Powerful, flexible and high-performance web hosting with mailbox, personal advisor and domain included 1time year !

SSL certificate
24/7 Support

Add password protection

You can add password protection by adding the following lines of code to the MongoDB configuration file:

   authorization: enabled

Now save the changes and close the file. Then restart MongoDB to apply the changes:

Create an administrator account

To create an administrator account, you will first need to launch the Mongo Shell:

You can then create a new database with the name “admin”:

You can now set your username and password by creating a new account:

     user: "monnomd'utilisateur", 
     pwd: "monmotdepasse", 
     roles: [ { role: "userAdmin", db: "admin" } ]

To quit the Mongo Shell, you can use the order quit(). Then reconnect to the Shell by entering your username and password after using the following command:

mongo --port 27017 --authenticationDatabase "admin" -u "monnomd'utilisateur" -p

Managing the administration of the database is therefore possible thanks to the Mongo Shell interface. It also allows, for example, to create other users and assign new functions to the database. Our MongoDB tutorial is at your disposal for more information on its use.

Uninstall MongoDB on Debian

It is of course also possible to uninstall MongoDB. However, an uninstallation is only recommended in certain cases:

Indeed, uninstalling MongoDB also deletes all databases that you have created so far.

Step 1: Stop MongoDB

Start by shutting down MongoDB using the following command:

Step 2: Remove MongoDB Packages

Now remove all the packages you have installed for MongoDB. For that, proceed as following :

sudo apt-get purge mongodb-org*

Step 3: Delete databases and log files

Finally, to complete the uninstallation of MongoDB on Debian, you must delete all databases created while using MongoDB as well as log files.

sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact


© 2024 AMZ DIGICOM All Rights Reserved