Home AlmaLinux How to Install MongoDB in RHEL, CentOS, Rocky & AlmaLinux

How to Install MongoDB in RHEL, CentOS, Rocky & AlmaLinux

The open-source attribute of MongoDB as a database software makes it an ideal candidate for almost any database-related project. Its popularity is in its embrace of NoSQL document-oriented databases.

While relational databases embrace the use of tables and rows to store data, MongoDB fancies the use of JSON-like documents which additionally supports the implementation of dynamic schemas.

The scalability and developer agility traits of MongoDB make it a worthwhile installation candidate for RHEL 8 based distributions such as CentOS, Rocky, and AlmaLinux.

Before we engage this post further, it is worth noting that the MongoDB database server release exists in two editions. We have the MongoDB Enterprise Server and the MongoDB Community Server (open source).

Installing MongoDB in RHEL-based Linux

Since we are going to focus on the installation and configuration of MongoDB Community Server, first ensure that you are a Sudoer user with privileges or have root user access on your system.

Afterward, proceed and update your system.

$ sudo dnf update

Regular system updates enable your operating system to have a better performance spectrum.

Next, we need to add MongoDB GPG Key and Repository Entry to the system in order to install the latest version of MongoDB.

$ sudo vi /etc/yum.repos.d/mongodb.repo
OR
$ sudo nano /etc/yum.repos.d/mongodb.repo

populate it with the following suggested data.

[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8Server/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc

We now need to run a system update for the second time for this new repository entry to be recognized.

$ sudo dnf update

We can now accomplish the installation of the MongoDB database server through the following command.

$ sudo dnf install mongodb-org -y

The database package installation will also consider other MongoDB dependencies as highlighted in the following screen capture. The installation process might take some time to complete. Therefore, be patient with it as it might also need to verify all its steps.

Install MongoDB in RHEL
Install MongoDB in RHEL

To start the service responsible for running MongoDB, execute the following command.

$ sudo systemctl start mongod

Let us now check on its status to confirm that the MongoDB database is up and running.

$ sudo systemctl status mongod
Check MongoDB in RHEL
Check MongoDB in RHEL

If you need the MongoDB database to keep running even after a successful system boot/reboot, run the command:

$ sudo systemctl enable mongod

If you need to restart, reload, and stop the MongoDB database, run:

$ sudo systemctl restart mongod
$ sudo systemctl reload mongod
$ sudo systemctl stop mongod

The default MongoDB port is 27017. The following command should unveil its port, address, version, and database status.

$ mongo --eval 'db.runCommand({connectionStatus: 1})'
Check MongoDB Port
Check MongoDB Port

Normal access to the MongoDB shell is achieved through the following command:

$ mongo
Connect MongoDB in RHEL
Connect MongoDB in RHEL

From here, you should be able to reference your MongoDB user manual for any commands that will help fasten your MongoDB learning experience.

With this MongoDB installation guide for RHEL systems, you should be comfortable enough to take your open-source database experience to the next level.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

1 thought on “How to Install MongoDB in RHEL, CentOS, Rocky & AlmaLinux”

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.