DebianLinuxTutorials

How To Install MongoDB on Debian 11

Install MongoDB on Debian 11

In this tutorial, we will show you how to install MongoDB on Debian 11. For those of you who didn’t know, MongoDB is a NoSQL database that is simple, object-oriented, scalable, and dynamic database. It is also called a NoSQL database because it does not rely on a traditional table-based relational database structure. It stores data in JSON format instead of the table style method. It can be integrated easily with various programming languages.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of the MongoDB NoSQL database on a Debian 11 (Bullseye).

Prerequisites

  • A server running one of the following operating systems: Debian 10 or Debian 11.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install MongoDB on Debian 11 Bullseye

Step 1. Before running the tutorial below, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt install curl apt-transport-https software-properties-common gnupg2

Step 2. Installing MongoDB.

By default, MongoDB is not available on Debian 11 base repository, Now add the MongoDB repository to your Debian 11 system:

echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" | tee /etc/apt/sources.list.d/mongodb-org.list

Next, add the GPG key with the following command:

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

After that, refresh APT and install MongoDB using the following command below:

sudo apt update
sudo apt install mongodb-org

To check the version of MongoDB which is installed:

mongod --version

Let’s enable and also start the service of the Database server so that we don’t need to run it again and again with system boot:

sudo systemctl start mongod
sudo systemctl enable mongod

To secure the MongoDB, launch the MongoDB:

mongo

Once you are connected, create a database named admin with the following command:

use admin

Then, create an admin user and set a password:

> db.createUser(
{
user: "ngadimin",
pwd: "your-strong-passwd",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)

To enable the security of MongoDB, open the configuration file of MongoDB:

nano /etc/mongod.conf

Add the following lines:

security:
 authorization: enabled

Save and close a file, then restart the MongoDB service to apply the changes:

sudo systemctl restart mongod

Verify MongoDB connection by running the following command to connect the MongoDB shell using the username and password:

mongo -u madmin -p

Congratulations! You have successfully installed MongoDB. Thanks for using this tutorial for installing the latest version of MongoDB 5 on the Debian system. For additional help or useful information, we recommend you check the official MongoDB website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button