×


Install MongoDB on Debian 10 - Step by step process to do it ?

MongoDB is a free and open-source document database. It belongs to a family of databases called NoSQL, which is different from the traditional table-based SQL databases like MySQL and PostgreSQL.
Previously, we have discussed how to install MongoDB on Ubuntu , Mint , and CentOS.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Software Installation tasks on Debian.
In this context, we shall look into How to install MongoDB on the Debian system.

How to install MongoDB on Debian ?

MongoDB's latest release is not available in the official repositories of Debian. Therefore, we will first need to add the MongoDB repository to our system and then install it.
We are going to install the latest release of MongoDB that is 4.4.
Here are the steps for the installation of MongoDB on the Debian system.

1. Import MongoDB GPG key

Import the MongoDB GPG key to your system’s list of trusted keys.
Here is the command to do so:

$ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add –

If you receive a "gnupg is not installed" error when adding the GPG key to your system, then install "gnupg" as follows:

$ sudo apt-get install gnupg

After the gnupg is installed, again run the above command to add the GPG key.

2. Add MongoDB Repository

Add MongoDB repository to your system. Here is the command to do so:

$ echo "deb [ arch=amd64,arm64 ]http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list


3. Update local package database

After adding the MongoDB repository to your system, update the local package database as follows:

$ sudo apt-get update


4. Install MongoDB

As the MongoDB repository and its GPG key have been added, now you can install MongoDB using the apt-get command as follows:

$ sudo apt-get install mongodb-org

You will be prompted with y/N, hit y. After this, the installation of MongoDB will be started.

5. Start MongoDB

After installation, MongoDB does not start automatically.
Therefore, you will have to manually start its service. Here is the command to start the MongoDB service:

$ sudo systemctl start mongod

After starting the MongoDB service, if you receive the service not found error, then first run the below command and after that try to start the service:

$ sudo systemctl daemon-reload

Now to check if the MongoDB service is started and running without any issues, run the below command:

$ sudo systemctl status mongod

You should see the active (running) status in the output.

If you want MongoDB to start automatically after a system reboot, run the below command:

$ sudo systemctl enable mongod

In some cases, you may need to stop the MongoDB service. Here is the command to do so:

$ sudo systemctl stop mongod

After making any configuration changes, you must restart the MongoDB service. Here is the command to do so:

$ sudo systemctl restart mongod


6. Connecting to MongoDB

Now to test if you can connect to the MongoDB server, run the below command:

$ mongo

This command will display the MongoDB version installed on your system.

How to uninstall MongoDB on Debian ?

There may come a time when you want to remove MongoDB from your system.
To do so, first stop the MongoDB service as follows:

$ sudo systemctl stop mongod

Then uninstall MongoDB as follows:

$ sudo apt-get purge mongodb-org*

You can also remove MongoDB databases and libraries.
Here are the commands to do so:

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


[Need urgent assistance to install missing Packages on Debian Linux Server? We are available to help you. ]


Conclusion

This article covers how to #install / #uninstall MongoDB on your Debian system. You have also learned how to manage MongoDB services.
MongoDB is an opensource, cross-platform NoSQL database server.
In MongoDB, data is stored in flexible, JSON-like documents where fields can vary from document to document.
It does not require a predefined schema, and data structure can be changed over time.

To install MongoDB on #Debian:
Perform the following steps as root or user with sudo privileges to install MongoDB on a Debian system.
1. Install the packages required for adding a new repository:

$ sudo apt install dirmngr gnupg apt-transport-https software-properties-common ca-certificates curl

2. Add the MongoDB GPG key to your system:

$ curl -fsSL https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

3. Enable the MongoDB repository:

$ sudo add-apt-repository 'deb https://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main'

4. Packages with older versions of MongoDB are not available for Debian 10.
Update the packages list and install the mongodb-org meta-package:

$ sudo apt update
$sudo apt install mongodb-org


The following packages will be installed on the system as a part of the mongodb-org package:
mongodb-org-server - The mongod daemon and corresponding init scripts and configurations.
mongodb-org-mongos - The mongos daemon.
mongodb-org-shell - The mongo shell is an interactive JavaScript interface to MongoDB. It is used to perform administrative tasks through the command line.
mongodb-org-tools - Contains several MongoDB tools for importing and exporting data, statistics, as well as other utilities.

To Start the #MongoDB service and enable it to start on boot:

sudo systemctl enable mongod --now