# How to install MongoDB on CentOS 7?

{% embed url="<https://youtu.be/kFphd4pD7Cs>" %}

### 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.&#x20;

### **Prerequisites**

There are certain prerequisites that need to be met before you begin:&#x20;

1. Server running CentOS 6 / CentOS 7 / CentOS 8&#x20;
2. Access to SSH connected text editor&#x20;
3. User account with root or sudo access&#x20;
4. Internet connection&#x20;

**Step 1: Enter as Root User**&#x20;

For making changes in the configuration file, you need to enter as a root user, with the following command:&#x20;

```
sudo -i 
```

**Step 2: Setting up Environment for MongoDB**&#x20;

* 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:&#x20;

```
nano /etc/yum.repos.d/mongodb-org-4.4.repo 
```

<figure><img src="http://customer.acecloudhosting.com/index.php?rp=/images/kb/1146_error-1.png" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**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:&#x20;
{% endhint %}

```
sudo -i 
```

```
yum install nano 
```

&#x20;

<figure><img src="http://customer.acecloudhosting.com/index.php?rp=/images/kb/1142_2.png" alt=""><figcaption></figcaption></figure>

When asked **Is this Ok**, enter **y** to continue the installation.&#x20;

* Add the following lines in the mongodb-org-4.4.repo configuration file:&#x20;

```
[mongodb-org-4.4]  

name=MongoDB Repository  

baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/  

gpgcheck=1  

enabled=1  

gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc  
```

&#x20;

<figure><img src="http://customer.acecloudhosting.com/index.php?rp=/images/kb/1143_3.png" alt=""><figcaption></figcaption></figure>

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.&#x20;

* Now that the MongoDB repository is added, use the following command to install the latest stable version of MongoDB:&#x20;

```
sudo yum install -y mongodb-org 
```

Executing this command will install the MongoDB package as well as all the necessary dependencies required for its proper functioning.&#x20;

&#x20;

<figure><img src="http://customer.acecloudhosting.com/index.php?rp=/images/kb/1144_4.png" alt=""><figcaption></figcaption></figure>

By now, you should have successfully installed MongoDB on your system.&#x20;

**Step 4: Start MongoDB Service**&#x20;

After the installation is complete, start the MongoDB service using the following command:&#x20;

```
systemctl start mongod.service 
```

To ensure that MongoDB starts automatically at system boot, run the following command:&#x20;

```
sudo systemctl enable mongod.service 
```

<img src="http://customer.acecloudhosting.com/index.php?rp=/images/kb/1145_6.png" alt="" height="64" width="800">

**Step 5: Verify MongoDB Installation**&#x20;

To verify the installation, use the following command to check the MongoDB service status:&#x20;

```
sudo systemctl status mongodb  
```

**Step 6: Connect to MongoDB**&#x20;

You can connect to the MongoDB server using the **mongo** shell command:&#x20;

```
mongo 
```

&#x20;\
This will open the MongoDB shell. You can now start using MongoDB.&#x20;

<figure><img src="http://customer.acecloudhosting.com/index.php?rp=/images/kb/1147_last.png" alt=""><figcaption></figcaption></figure>

### Conclusion

&#x20;You have successfully installed MongoDB on your CentOS 7 server. You can now start using MongoDB to manage your data.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.acecloud.ai/knowledge-base/tutorials/how-to-install-mongodb-on-centos-7.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
