How To Install MongoDB on CentOS 7

MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need.

  • MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time

  • The document model maps to the objects in your application code, making data easy to work with

  • Ad hoc queries, indexing, and real time aggregation provide powerful ways to access and analyze your data

  • MongoDB is a distributed database at its core, so high availability, horizontal scaling, and geographic distribution are built in and easy to use

  • MongoDB is free and open-source, published under the GNU Affero General Public License


Installation procedures:

Step 1. Add the MongoDB Repository:

The mongodb-org package does not exist within the default repositories for CentOS. However, MongoDB maintains a dedicated repository. Let’s add it to our server.

With the vi editor, create a .repo file for yum, the package management utility for CentOS:

vi /etc/yum.repos.d/mongodb.repo

Option A: If you are running a 64-bit system, add the following information to the file you have created.

name=MongoDB Repository

Then exit and save the file.

Option B: If you are running a 32-bit system, add the following information to the file you’ve created, using i to insert:

name=MongoDB Repository

Then exit and save the file. I believe everyone is aware how to edit and save a file in vi editor.


Step 2. Install MongoDB:

yum -y install mongodb-org mongodb-org-server

Note: Here I have given ‘-y’ in the above command, this tell that we are by default typed “yes” for all the confirmation that are going to ask in the installation process. You do need to enter”yes” or “y” while installation.


Step 3. Get MongoDB Running:

Start MongoDB:

systemctl start mongod

Check MongoDB Service Status:

systemctl status mongod

Note: The systemctl utility did not provide a result after executing the start command, but we can check that the service started by viewing the end of the mongod.log file with the tail command:

tail /var/log/mongodb/mongod.log

Step 4. Verifying Startup:

Because a database-driven application cannot function without a database, we’ll make sure that the MongoDB daemon, mongod, will start with the system.

Use the systemctl utility to check its startup status:
systemctl is-enabled mongod; echo $?

An output of zero confirms an enabled daemon, which we want. A one, however, confirms a disabled daemon that will not start.
. . .
In the event of a disabled daemon, use the systemctl utility to enable it:
systemctl enable mongod

Summary List of Status Statistics (Continuous)


Summary List of Status Statistics (5 Rows, Summarized Every 2 Seconds):

mongostat --rowcount 5 2

Enter the MongoDB Command Line:



By default, running this command will look for a MongoDB server listening on port 27017 on the localhost interface.

If you’d like to connect to a MongoDB server running on a different port, then use the –port option. For example, if you wanted to connect to a local MongoDB server listening on port 33333, then you’d issue the following command:

mongo --port 33333

Thank you.


Powered by Facebook Comments

Be the first to comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.