How to Install MongoDB Community Edition 6.0 on Red Hat or CentOS?
To install the latest MongoDB Community Edition on the Red Hat or CentOS operating system, follow the steps mentioned below. The commands are the same for both OS, however, this blog will show the outputs of CentOS:
Step 1: Add MongoDB Repository on Red Hat or CentOS
As the latest stable edition is MongoDB Community 6.0, so let us create a MongoDB repository configuration file with the name “mongodb-org-6.0.repo” using the nano editor:
Output
The terminal prompts the password and opens a new file.
Copy and paste this code into the newly created configuration file of the MongoDB repository:
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
Output
Save the code and exit the nano editor by pressing the “CTRL + X” keys.
Step 2: Install the Latest Edition of MongoDB Community
To install the latest MongoDB Community Edition, execute the command given below:
Output
The installation will consume some time.
Wait for the process installation process to complete:
The latest MongoDB Community Edition is installed successfully.
Sometimes the user wants to install any specific version of MongoDB Community, such as “5.0.17”, “4.4.21” and “6.0.5”. For that purpose, enlist each product with the version number in the command as shown:
Output
The specified edition of MongoDB Community is installed successfully.
Step 3: Verify the Installation of MongoDB Community Edition
To verify whether the installation is complete or not, execute this command to see the details of the installed MongoDB Server:
Output
The output returned the details of the latest MongoDB Server along with its version.
Step 4: Manage the MongoDB Server Services
The commands are listed below to manage the MongoDB Server services in Red Hat or CentOS.
Start the service of MongoDB server by using this command:
To see the status of the MongoDB server service, utilize this command:
Output
The output shows that the MongoDB server started successfully.
If any error prompts and the server does not start, run this command:
After running the reload command, enable the server by using the given command:
Run the status command to verify the status of the server.
Output
Sometimes, the user needs to stop the services manually. For that purpose, run this command and the status command to see its effect:
Output
The output displays that the MongoDB server service stopped successfully.
To restart this service, execute the command mentioned below:
Output
The MongoDB Server Service is running.
Conclusion
To install the latest MongoDB Community Edition 6.0 on Red Hat or CentOS, create a MongoDB repository configuration file and paste the code provided in the blog to configure the MongoDB repository. After that, install the latest edition using the “sudo yum install -y mongodb-org” command. Once the MongoDB Community edition is installed, manage the MongoDB server services using “systemctl” commands.