MongoDB is an open-source and free database service that is a NoSQL Database and is different from other databases like MSSQL and MySQL. 

There is no requirement for a predefined schema and data structure, as it will be changed. Data will be stored in JSON-like documents in MongoDB.

(We assume you are logged in with root or sudo user.)

The following are the steps to install MongoDB 4 on CentOS 7 – 

Step 1: Add the MongoDB repository to mongodb-org.repo inside the /etc/yum.repos.d/ directory using command:

# sudo vi /etc/yum.repos.d/mongodb-org.repo

Step 2: Enter the details below in mongodb-org.repo

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

Step 3: Once the repository is enabled, install MongoDB using the Yum command as below.

# sudo yum install -y mongodb-org

When prompted for the GPG key, type y and press Enter.

The following packages will be installed:

  • mongodb-org-server – The MongoDB server process

  • mongodb-org-mongos – The MongoDB sharding router

  • mongodb-org-shell – The interactive MongoDB shell

  • mongodb-org-tools – Tools for database export, import, and diagnostics          

Step 4: Start MongoDB and enable it to start on boot.

# sudo systemctl start mongod
# sudo systemctl enable mongod

Step 5: You can use the Mongo command to verify the installation MongoDB version.

# mongo

mongo-installed-version.png

MongoDB 4 is now installed and running on CentOS 7. You can start creating databases and collections right away.

Was this answer helpful? 0 Users Found This Useful (1 Votes)