(Last Updated On: August 23, 2019)

How can I install MongoDB 4 on Debian 10 (Buster)?. MongoDB is an open source NoSQL database written in C++ for massive scalability, high performance, and availability. As of this article update, the repositories available are for Debian 9. We will add some hacks to Install MongoDB 4 on Debian 10 (Buster). But once the repository is available for Debian 10, this article will be updated.

Here are the steps you’ll need to Install MongoDB 4 on Debian 10 (Buster). I’m doing this setup on a fresh minimal installation of Debian 10 server. This is recommended to ensure you don’t break running applications dependencies.

Step 1: Add MongoDB repository

We will do a system update and add MongoDB repository for Debian Stretch.

sudo apt update
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org.list
echo "deb http://deb.debian.org/debian/ stretch main" | sudo tee /etc/apt/sources.list.d/debian-stretch.list

Step 2: Install libcurl3

The libcurl3 package is required by mongodb-org-server. Since the default version for Debian 10 is libcurl4, this package will be downloaded from added Debian 9 repository.

sudo apt update
sudo apt -y install libcurl3

Step 3: Install MongoDB Server on Debian 10 (Stretch)

We have added required repositories and installed libcurl3. Let’s now install MongoDB Server on Debian 10 (Stretch).

sudo apt -y install mongodb-org

Get package information with apt info command.

$ apt info mongodb-org
Package: mongodb-org
Version: 4.0.12
Priority: optional
Section: database
Maintainer: Ernie Hershey [email protected]
Installed-Size: 13.3 kB

The installation of the above package will install the following dependency packages:

mongodb-org-server – This provides MongoDB daemon mongod
mongodb-org-mongos – This is a MongoDB Shard daemon
mongodb-org-shell – This provides a shell to MongoDB
mongodb-org-tools – MongoDB tools used for export, dump, import e.t.c

Step 4: Start MongoDB Server on Debian 10 (Stretch)

The server daemon is named mongod. Start and set it to start on server reboot/boot up.

sudo systemctl enable --now mongod

Check its running status.

$ systemctl status  mongod.service
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-08-22 23:40:54 CEST; 4s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 5939 (mongod)
   Memory: 48.6M
   CGroup: /system.slice/mongod.service
           └─5939 /usr/bin/mongod --config /etc/mongod.conf

Aug 22 23:40:54 debian1 systemd[1]: Started MongoDB Database Server.
Aug 22 23:40:54 debian1 mongod[5939]: 2019-08-22T23:40:54.447+0200 I STORAGE  [main] Max cache overflow file size custom option: 0

The service listens on localhost TCP port 27017 by default.

$ ss -tunelp
Netid   State    Recv-Q   Send-Q     Local Address:Port        Peer Address:Port                                                                   
udp     UNCONN   0        0                0.0.0.0:68               0.0.0.0:*       users:(("dhclient",pid=440,fd=7)) ino:13373 sk:1 <->           
tcp     LISTEN   0        128            127.0.0.1:27017            0.0.0.0:*       users:(("mongod",pid=5939,fd=11)) uid:106 ino:35394 sk:2 <->   
tcp     LISTEN   0        128              0.0.0.0:22               0.0.0.0:*       users:(("sshd",pid=602,fd=3)) ino:14676 sk:3 <->               
tcp     LISTEN   0        128                 [::]:22                  [::]:*       users:(("sshd",pid=602,fd=4)) ino:14678 sk:4 v6only:1 <->

This setting can be altered on the /etc/mongod.conf file.

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

The IP 127.0.0.1 can be replaced with an IP address on the server’s network interface to bind to.

Restart mongod service if a change is made.

sudo systemctl restart mongod

To get to MongoDB shell, run:

$ mongo
MongoDB shell version v4.0.12
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("612cf3d6-23db-4a4d-9c71-c052ef1090d8") }
MongoDB server version: 4.0.12
Server has startup warnings: 
2019-08-22T23:44:48.131+0200 I STORAGE  [initandlisten] 
2019-08-22T23:44:48.131+0200 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-08-22T23:44:48.131+0200 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-08-22T23:44:49.478+0200 I CONTROL  [initandlisten] 
2019-08-22T23:44:49.478+0200 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-08-22T23:44:49.478+0200 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-08-22T23:44:49.478+0200 I CONTROL  [initandlisten] 
2019-08-22T23:44:49.479+0200 I CONTROL  [initandlisten] 
2019-08-22T23:44:49.479+0200 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-08-22T23:44:49.479+0200 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-08-22T23:44:49.479+0200 I CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> 

More reading:  How to configure MongoDB 4 authentication.

Installing MongoDB 4 on other systems:

How to Install MongoDB 4 on CentOS 7

How to Install MongoDB 4 on RHEL 8 / CentOS 8

How to install Latest MongoDB on Ubuntu 18.04 / Ubuntu 16.04