How To Install MongoDB on Rocky Linux 9

Install MongoDB on Rocky Linux 9

In this tutorial, we will show you how to install MongoDB on Rocky Linux 9. For those of you who didn’t know, MongoDB is one of the popularly used general-purpose, object-oriented NoSQL databases. Unlike relational databases such as MySQL, Oracle, and SQL servers which store data in tables according to a rigid schema, MongoDB stores data in documents with flexible schema. MongoDB is available for Windows, Linux, and macOS systems supporting both 32 and 64-bit systems.

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 the step-by-step installation of the MongoDB NoSQL database on Rocky Linux. 9.


  • A server running one of the following operating systems: Rocky Linux 9.
  • 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 useror 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 Rocky Linux 9

Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:

sudo dnf check-update
sudo dnf install dnf-utils

Step 2. Installing MongoDB Database on Rocky Linux 9.

By default, MongoDB is not available on Rocky Linux 9 base repository. Now run the following command below to add the MongoDB repository to your system:

sudo tee /etc/yum.repos.d/mongodb-org-6.0.repo<<EOF
name=MongoDB Repository

After the repository has been added, you can install MongoDB using the following command below:

sudo dnf install mongodb-org

Alternatively, to install a specific release of MongoDB, specify each component package individually and append the version number to the package name, as in the following example:

sudo dnf install mongodb-org-<VERSION> mongodb-org-database-<VERSION> mongodb-org-server-<VERSION> mongodb-mongosh-<VERSION> mongodb-org-mongos-<VERSION> mongodb-org-tools-<VERSION>

Let’s check the version of MongoDB we have just installed:

mongod --version


db version v6.0.0
Build Info: {
    "version": "6.0.0",
    "gitVersion": "e61bf27c2gdt83fed36e5a13c00732d563mei2",
    "openSSLVersion": "OpenSSL 1.4.2k  25 Sep 2022",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "rhel80",
        "distarch": "x86_64",
        "target_arch": "x86_64"

Once the service has been installed, it will not be started by default. Start the MongoDB service using this command:

sudo systemctl start mongod
sudo systemctl enable mongod

Step 3. Securing MongoDB.

By default, MongoDB is not hardened. To improve security, you need to create a user and set a password:


Now create a user and set a password using the following command below:

use admin

user: "mongouser",
pwd: passwordPrompt(), // or cleartext password
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]

Now for the authentication to be enabled, you need to edit the MongoDB config file:

nano /etc/mongod.conf

Edit the following line:

    authorization: "enabled"

Save and close the file, then restart the MongoDB service to apply the effect of the change:

sudo systemctl restart mongod

Step 4. Accessing the MongoDB.

You can now try to access the MongoDB from the local host using the command:

mongosh -u mongouser

To check the current database you are operating on type db:

$ db 

Congratulations! You have successfully installed MongoDB. Thanks for using this tutorial for installing the MongoDB NoSQL database on your Rocky Linux 9 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!