In this article, I am going to show you how to install MongoDB 4 on Debian 10 and solve the unmet dependency problems. I will also give you hints along the way to install MongoDB when Debian 10 is officially supported.
I will be using minimal installation of Debian 10 operating system for the demonstration. But, it will also work on Debian 10 desktop operating systems. So, let’s get started.
Adding GPG Key of MongoDB Repository:
You have to install wget and gnupg in order to download and add the GPG key of MongoDB official package repository to Debian 10.
First, update the APT package repository cache with the following command:
The APT package repository cache should be updated.
Now, install wget and gnupg with the following command:
Now, press Y and then press <Enter> to confirm the installation.
wget and gnupg should be installed.
Now, run the following command to add the GPG key of the MongoDB official package repository on your Debian 10 machine.
| sudo apt-key add -
The GPG key should be added.
Adding the Official Package Repository of MongoDB 4:
At the time of this writing, there is no official package repository of MongoDB 4 for Debian 10. But, we can use the Debian 9 package repository on Debian 10 as long as there is no official package repository is available for Debian 10.
To add the official MongoDB 4 package repository for Debian 9 on Debian 10, run the following command.
| sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
The official MongoDB 4 package repository of Debian 9 should be added to your Debian 10 machine.
NOTE: If in future, there is any official MongoDB package repository available for Debian 10, you may be able to add it as follows.
| sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
Now, update the APT package repository cache with the following command:
Installing MongoDB 4:
To install MongoDB 4, you have to run the following command.
If MongoDB had an official Debian 10 package repository, then this command would be enough to install MongoDB 4. As I am using official MongoDB package repository of Debian 9 on Debian 10, if I try to install MongoDB 4 like this, I will get an error as you can see in the screenshot below.
Let’s try to see why mongodb-org-server is not going to be installed.
Well, mongodb-org-server requires libcurl3. But, Debian 10 uses libcurl4. It does not have any libcurl3 support.
To solve this problem, we can add the official Debian 9 package repository on Debian 10 and install libcurl3 library package from there.
To add the official Debian 9 package repository on Debian 10, run the following command:
| sudo tee /etc/apt/sources.list.d/debian-stretch.list
The official Debian 9 package repository should be added on your Debian 10 machine.
Now, update the APT package repository cache with the following command:
The APT package repository cache should be updated.
Now, install libcurl3 with the following command:
Now, press Y and then press <Enter> to confirm the installation.
libcurl3 should be installed.
Now, install MongoDB 4 with the following command:
Now, press Y and then press <Enter> to confirm the installation.
MongoDB 4 should be installed.
Now, run the following command to check whether MongoDB 4 is working correctly.
As you can see, I am running MongoDB 4.0.11 and it’s working correctly.
Managing MongoDB Services:
Now, check whether MongoDB service is running with the following command:
As you can see, the MongoDB service is inactive, which means it’s not running. The MongoDB service is also disabled, which means it is not added to the system startup yet. So, it won’t start automatically on system reboot.
Now, start the MongoDB service with the following command:
If you check the MongoDB service status again, MongoDB service should be active/running as you can see in the screenshot below. Great!
Now, add MongoDB service to the system startup of your Debian 10 machine with the following command:
MongoDB service should be added to the system startup and it will start automatically on system boot from now on.
To remove MongoDB service from the system startup, run the following command:
If you want to stop the MongoDB service, run the following command:
If you want to restart the MongoDB service, run the following command:
You should be connected to the MongoDB 4 server. Here, you can run any MongoDB 4 queries.
Now, create a new database test and use it as follows:
Now, create a new collection users in the test database and insert an entry to the users collection as follows:
Now, list all the entries of the users collection as follows:
As you can see, the entry we’ve inserted earlier is listed. So, MongoDB is working correctly.
Now, exit out of Mongo Shell with the following query.
So, that’s how you install MongoDB 4 on Debian 10. Thanks for reading this article.