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.
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
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})'
Normal access to the MongoDB shell is achieved through the following command:
$ mongo
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.
EOL Notice…
MongoDB 5.0 Community Edition removes support for RHEL / CentOS / Oracle 6 on x86_64.