How to Install MongoDB on Debian 10 (Buster)
Because I couldn't find proper and working documentation for installing mongoDB on Debian 10 (Buster), I thought it would be useful to describe how I literally lost time with it.
Prerequisites
This guide assumes that you are using Debian 10. Before you begin, you should have a non-root user with sudo privileges set up on your system. You can learn how to set this up by following the initial server setup for Debian 10 tutorial.
Step 1. Add MongoDB repository
At the moment, the mongoDB repository simply doesn't have a stable version 4 of the database for Debian 10, so we'll have to go round the clock and look for everything ourselves (good thing I already did).
First, we need to add the MongoDB signing key with apt-key add
. We’ll need to make sure the curl
command is installed before doing so:
~$ sudo apt install curl
Next we download the key and pass it to apt-key add
:
~$ curl https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
Next we’ll create a source list for the MongoDB repo, so apt
knows where to download from. To do this, we execute the command:
~$ echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/development main" | sudo tee /etc/apt/sources.list.d/mongodb-org.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. To return the curl command to work, follow the steps described in this article.
~$ echo "deb http://deb.debian.org/debian/ stretch main" | sudo tee /etc/apt/sources.list.d/debian-stretch.list ~$ sudo apt update ~$ sudo apt -y install libcurl3
Step 3. Install MongoDB Server on Debian 10 (Buster)
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.2.1~latest Priority: optional Section: database Maintainer: Ernie Hershey <ernie.hershey@mongodb.com> Installed-Size: 13.3 kB Depends: mongodb-org-shell, mongodb-org-server, mongodb-org-mongos, mongodb-org-tools
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 etc
Step 4. Start MongoDB Server on Debian 10 (Buster)
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:
~$ sudo systemctl status mongod ● mongod.service - MongoDB Database Server Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-10-18 14:53:55 MSK; 4s ago Docs: https://docs.mongodb.org/manual Main PID: 6596 (mongod) Memory: 78.5M CGroup: /system.slice/mongod.service └─6596 /usr/bin/mongod --config /etc/mongod.conf Oct 18 14:53:55 220943.simplecloud.ru systemd[1]: Started MongoDB Database Server.
If you have caught an error the first time you run it, the following steps are likely to help you:
~$ sudo systemctl stop mongod ~$ sudo rm -rf /var/lib/mongodb ~$ sudo mkdir /var/lib/mongodb ~$ sudo chown -R mongodb:mongodb /var/lib/mongodb ~$ sudo systemctl start mongod
The service listens on localhost TCP port 27017 by default, check it:
~$ ss -tunelp Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port udp UNCONN 0 0 96.123.217.94%eth0:68 0.0.0.0:* uid:102 ino:82671 sk:1 <-> udp UNCONN 0 0 0.0.0.0:68 0.0.0.0:* ino:14242 sk:2 <-> tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* ino:15174 sk:3 <-> tcp LISTEN 0 128 127.0.0.1:27017 0.0.0.0:* uid:106 ino:259576 sk:7 <-> tcp LISTEN 0 128 0.0.0.0:80 0.0.0.0:* ino:144683 sk:4 <-> tcp LISTEN 0 128 [::]:22 [::]:* ino:15185 sk:5 v6only:1 <-> tcp LISTEN 0 128 [::]:80 [::]:* ino:144684 sk:6 v6only:1 <->
That's all, thanks for reading.