How to install MongoDB 5.0 Server on Debian 11 Bullseye – Guide

This guide provides a systematic demonstration of how to Install MongoDB 5.0 on Debian 11 / Debian 10 Linux systems. MongoDB is a general-purpose, object-oriented, simple and dynamic database. It is a NoSQL document store. This means that data objects are stored as separate documents in a collection. This helps to overcome the relational database approach. MongoDB is written in C++ for great scalability and high performance. It is available for Windows, macOS and Linux operating systems and supports both 32-bit and 64-bit architectures. MongoDB 5.0 brings news features such as: MongoDB is good for the following:

Step 1: Add MongoDB APT repository in Debian 11 / Debian 10

In that guide, we will install MongoDB 5.0 using the apt manager. Here, we will use the official mongo-org package. This package is supported and maintained by MongoDB Inc. The Mongo-org package always contains the latest available versions of MongoDB. First, we import MongoDB’s public GPG key. Download using wget as below. Install wget on Debian 11 / Debian 10 using sudo apt install wget wget -qO – https://www.mongodb.org/static This code should respond with OK as output. However, if you get an error indicating that GnuPG is not installed, install it as follows. sudo apt update sudo apt-get install gnupg2 With GnuPG installed, try importing the key again: wget -qO – https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add – The next step requires us to create a /etc/apt/sources.list.d/mongodb-org-5.0.list file for MongoDB 5.0. We will use the buster repository for both distros as at the time of documenting this article the bullseye repository did not exist. echo “deb http://repo.mongodb.org/apt/debian buster / mongodb-org / 5.0 main” | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list Then update your local package database as below. $ sudo apt-get update Hit: 1 http://deb.debian.org/debian buster InRelease Hit: 2 http://security.debian.org/debian-security buster / InRelease updates Hit: 3 http://deb.debian.org/debian buster-updates InRelease Ign: 4 http://repo.mongodb.org/apt/debian buster / mongodb-org / 5.0 InRelease Get: Version 5 http://repo.mongodb.org/apt/debian buster / mongodb-org / 5.0 [2,396 B] Get: 6 http://repo.mongodb.org/apt/debian buster / mongodb-org / 5.0 Release.gpg [801 B] Get: 7 packages http://repo.mongodb.org/apt/debian buster / mongodb-org / 5.0 / main amd64 [6,551 B] Searched 9,748 B in 3s (3,461 B / s) Reading package lists… Done

Step 2: Install MongoDB 5.0 on Debian 11 / Debian 10

In that guide, we will install a specific version, namely 5.0.2, and therefore we will specify each component package with the version number below. sudo apt-get install -y mongodb-org mongodb-org-database mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools If you choose to install mongodb-org = 5.0.2 without specifying the component version, the latest version of each component will be installed. Dependency tree of the above command: Building dependency tree Reading status information… Done The following additional packages will be installed: mongodb-database-tools mongodb-mongosh mongodb-org-database-tools-extra The following NEW packages will be installed: mongodb-database-tools mongodb-mongosh mongodb-org mongodb-org-database mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools 0 updated, 9 newly installed, 0 to remove and 2 not updated. Need to get 147 MB ​​of files. After this operation, 449 MB of additional disk space will be used. With MongoDB 5.0 installed, we can now configure our system. First, start and enable the mongod service on Debian 11 / Debian 10 as below. sudo systemctl start mongod sudo systemctl enable mongod Check the MongoDB version installed. $mongod -version db version v5.0.2 Build information: { “Version”: “5.0.2”, “GitVersion”: “6d9ec525e78465dcecadcff99cce953d380fedc8”, “OpenSSLVersion”: “OpenSSL 1.1.1k 25 Mar 2021”, “Modules”: [], “Allocator”: “tcmalloc”, “environment”: { “Distmod”: “debian10”, “Distarch”: “x86_64”, “Target_arch”: “x86_64” } }

Step 3: Configure MongoDB on Debian 11 / Debian 10.

Check if the service is running: $systemctl status mongod ● mongod.service – MongoDB database server Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor default: enabled) Active: active (running) since Sat 2021-08-21 07:49:24 EDT; 39s ago Documents: https://docs.mongodb.org/manual Main PID: 5029 (mongod) Memory: 71.4M CGroup: /system.slice/mongod.service └─5029 / usr / bin / mongod –config /etc/mongod.conf 21 Aug 07:49:24 ns1.computingforgeeks.local systemd[1]: Started MongoDB database server. 21 Aug 07:49:29 ns1.computingforgeeks.local systemd[1]: /lib/systemd/system/mongod.service:11: PIDFile = reference path under legacy directory /var/run….

Secure instance of MongoDB 5.0.

After installation, the MongoDB database is unsecured, you can access it without a password and make unwanted changes to your database. Therefore, we need to secure this database by creating a username and password. Connect to the database by issuing the code: $mongo Then add a user named mongouser, remember that you can change that name to whatever name you want. with the script below added, it is necessary to set a password for the user. use admin db.createUser( { user: “mongouser”, pwd: passwordPrompt(), // or plain text password roles: [ { role: “userAdminAnyDatabase”, db: “admin” }, “readWriteAnyDatabase” ] } ) Sample output to script.

use admin changed to db admin db.createUser( … { … user: “mongouser”, … Pwd: passwordPrompt(), // or plain text password … Functions: [ { role: “userAdminAnyDatabase”, db: “admin” }, “readWriteAnyDatabase” ] …} …) Type the password: User successfully added: { “User”: “mongouser”, “Functions”: [ { “role” : “userAdminAnyDatabase”, “db” : “admin” }, “readWriteAnyDatabase” ] } exit bye Then edit the MongoDB configuration file and enable authentication. sudo apt install vim sudo vim /etc/mongod.conf In the file, find the #security line, uncomment it and add authentication. Be sure to add double space before authorization as syntax is very important here. Your file should appear as below. safety: authorization: enabled For the changes made to take effect, restart the MongoDB service. sudo systemctl restart mongod Clients now need to authenticate themselves to access the database. The syntax used is as follows. mongo –port 27017 –authenticationDatabase “admin” -u “your-user” -p

Step 4: Using MongoDB 5.0 on Debian 11 / Debian 10.

MongoDB listens on a default port of 27017. From localhost connect to user created using mongo -u mongouser -p –authenticationDatabase admin Enter the password you created earlier to connect to your database.

Step 5: Change the default MongoDB path in Debian 11 / Debian 10

The default path used as storage for MongoDB data is /var/lib/mongo. However, this directory can be changed as below. Stop the MongoDB service. sudo systemctl stop mongod.service 2. Create a new directory for MongoDB data. sudo mkdir -p / data / computingforgeeks / mongo Set the directory as a property of MongoDB. sudo chown -R mongodb: mongodb / data / computingforgeeks / mongo 3. Copy the content to the new directory. Install Rsync using sudo apt install rsync sudo rsync -av / var / lib / mongodb / data / computingforgeeks / mongo 4. Rename the old directory for backup. sudo mv / var / lib / mongodb /var/lib/mongodb.bak 5. Create a symbolic link to the new location. sudo ln -s / data / computingforgeeks / mongo / var / lib / mongodb With these changes made, restart the MongoDB service. MongoDB will start using the newly created directory to store your data. sudo systemctl start mongod.service

Final note

I hope you like the guide How to install MongoDB 5.0 Server on Debian 11 Bullseye. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.

How to install MongoDB 5 0 Server on Debian 11 Bullseye  2022  - 17How to install MongoDB 5 0 Server on Debian 11 Bullseye  2022  - 82How to install MongoDB 5 0 Server on Debian 11 Bullseye  2022  - 80How to install MongoDB 5 0 Server on Debian 11 Bullseye  2022  - 36