How to Install MongoDB 4 on Debian 10

MongoDB is an opensource, cross-platform NoSQL database server that developed by MongoDB Inc. It uses JSON to store its data and is popular for handling large amounts of data due to its scalability, high availability, and high performance.

In this tutorial, you will learn how to install MongoDB 4 on Debian 10 Linux distribution.

Step 1: Importing MongoDB GPG Key on Debian

To start off, you need to import the GPG key that is required by the MongoDB repository for your Debian system. This is crucial for testing packages prior to installation.

First, update your system packages using the following apt command.

$ sudo apt update
Update Debian 10 Buster
Update Debian 10 Buster

To import the MongoDB GPG key, run the command.

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Add MongoDB Repository Key
Add MongoDB Repository Key

With that done, now add the MongoDB APT repository on your Debian system as explained below.

Step 2: Installing MongoDB 4 APT Repository on Debian

At the time of penning down this article, MongoDB 4 does not have official Package repositories for Debian 10. But worry not. You can still add the package repository of Debian 9 (Stretch) on Debian 10 (Buster) to make up for that.

To add MongoDB 4 package repository of Debian 9 on Debian 10 Buster, execute the command.

$ echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org.list

To add the official repository of Debian 9 on Debian 10 Buster, issue the command.

$ echo "deb http://deb.debian.org/debian/ stretch main" | sudo tee /etc/apt/sources.list.d/debian-stretch.list
Add MongoDB Repository on Debian
Add MongoDB Repository on Debian

Next, update the APT repository using the command.

$ sudo apt update
Update APT Repository
Update APT Repository

Step 3: Installing libcurl3 on Debian

The package libcurl3 is required by mongodb-org-server which we are going to install later on. Without libcurl3, you will encounter errors trying to install MongoDB.

It is also worth mentioning that Debian 10 uses libcurl4, but since we added Debian 9‘s official repository, the libcurl3 package will be installed from the added repository.

To install libcurl3, run the command.

$ sudo apt install libcurl3
Install libcurl3 on Debian
Install libcurl3 on Debian

Step 4: Installing MongoDB 4 Server on Debian

Having installed the required repositories and libcurl3 package, you can now proceed to install MongoDB 4 server.

$ sudo apt install mongodb-org -y
Install Mongodb Server on Debian
Install MongoDB Server on Debian

To check the version of MongoDB installed issue the APT command as shown.

$ sudo apt info mongodb-info
Check MongoDB Version
Check MongoDB Version

By default, MongoDB runs on port 27017 and you can verify it using the netstat command as shown.

$ sudo netstat -pnltu
Check MongoDB Port
Check MongoDB Port

To change the default MongoDB port and other parameters, edit the configuration file found at /etc/mongodb.conf.

Change MongoDB Default Port
Change MongoDB Default Port

Step 5: Managing MongoDB 4 Server

Once you have successfully installed MongoDB 4 server, start it using the command.

$ sudo systemctl start mongod

To check the status of a MongoDB service run the command.

$ sudo systemctl status mongod
Check MongoDB Status
Check MongoDB Status

To enable MongoDB to start on boot, run the command.

$ sudo systemctl enable mongod

To log into MongoDB 4 simply run the command.

$ mongo
Access MongoDB Shell
Access MongoDB Shell

To stop MongoDB run.

$ sudo systemctl stop mongod

And that’s just about it. In this guide, we have demonstrated how you can install MongoDB 4 on Debian 10.

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

1 Comment

Leave a Reply

Leave a Reply to mirko tebaldi Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.