How To Setup MongoDB on CentOS 7

Install MongoDB on CentOS

In this blog, you will learn how to install MongoDB in CentOS using ‘yum’.

By default, the ‘yum‘ repo does not have a MongoDB package. However, you can add a repository to the yum package management system. Follow the below steps to install MongoDB on CentOS.

Follow the below steps to install MongoDB on CentOS using ‘yum’.

Step-1:  Update applications on the system.

 yum update 

‘yum update’ will update all the available repository and update it with the latest version.

Step-2:  Update the MongoDB package in the yum repository to install MongoDB on CentOS.

By default, the MongoDB repository is not available in the yum repo. To use the yum repo, we need to add manually the MongoDB details. Create a repo file inside the yum.repo.d directory. Here I have created a repro for MongoDB 3.6. Based on the required version, you can create a repo file and add the repository details.

vim /etc/yum.repos.d/mongodb-org-3.6.repo 

Add MongoDB repository details to the repo file.

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

Save the file and exit.

Other versions of the MongoDB repository can be found here.

Step-3:  Setup MongoDB.

Once the repo file is ready, use the below command to install MongoDB using yum.

 sudo yum install mongodb-org 

Step-4:  Start MongoDB.

Upon successfully installed, start the MongoDB daemon using the command below.

 sudo systemctl start mongod

To enable MongoDB to start at boot by using the following command.

 sudo systemctl enable mongod

Step-5:  Restart MongoDB.

Use the below command to restart the MongoDB server.

 sudo systemctl restart mongod

Step-6:  Verify the installation.

Once the MongoDB os successfully installed, connect to the MongoDB shell to verify the installation.

 mongo 

Step-7:  Stop MongoDB.

 sudo systemctl stop mongod 

In this blog, you have learned how to install MongoDB on CentOS using yum. Follow other tutorials for more information.

Leave a Reply