How to install MongoDB on CentOS 7?
Overview
MongoDB is a widely used open-source NoSQL database management system. It is highly scalable and provides high performance for large data sets. In this guide, we will walk you through the step-by-step process of installing MongoDB on a CentOS 7 server.
Prerequisites
There are certain prerequisites that need to be met before you begin:
Server running CentOS 6 / CentOS 7 / CentOS 8
Access to SSH connected text editor
User account with root or sudo access
Internet connection
Step 1: Enter as Root User
For making changes in the configuration file, you need to enter as a root user, with the following command:
Step 2: Setting up Environment for MongoDB
The MongoDB repository is not included in the default CentOS 7 package repositories. Therefore, you need to add it manually. Create a MongoDB repository file under the /etc/yum.repos.d/ directory using the following command:
Note: If you get the error nano: command not found, enter as root user and then install the nano text editor, using the following command:
When asked Is this Ok, enter y to continue the installation.
Add the following lines in the mongodb-org-4.4.repo configuration file:
Once, you have added the lines in the configuration file, save and close it using the commands Ctrl + O, press enter and then enter Ctrl +X.
Now that the MongoDB repository is added, use the following command to install the latest stable version of MongoDB:
Executing this command will install the MongoDB package as well as all the necessary dependencies required for its proper functioning.
By now, you should have successfully installed MongoDB on your system.
Step 4: Start MongoDB Service
After the installation is complete, start the MongoDB service using the following command:
To ensure that MongoDB starts automatically at system boot, run the following command:
Step 5: Verify MongoDB Installation
To verify the installation, use the following command to check the MongoDB service status:
Step 6: Connect to MongoDB
You can connect to the MongoDB server using the mongo shell command:
This will open the MongoDB shell. You can now start using MongoDB.
Conclusion
You have successfully installed MongoDB on your CentOS 7 server. You can now start using MongoDB to manage your data.
Last updated