How to install MongoDB in CentOS 7

Share this post to your friends !

SystemMen - How to install MongoDB in CentOS 7? This article will guide you step by step how to install it successfully.

MongoDB is a well-known database type, many large systems are using it, especially the development of IoT.

Add MongoDB repository to the server

First, just like database types like MariaDB, MongoDB allows you to install it through the repository.

Type the command below to create MongoDB repository file.

yum install nano -y && nano /etc/yum.repos.d/mongodb-org-4.0.repo

Then, copy the text below into the file above and save it.

name=MongoDB Repository

Install MongoDB in CentOS 7

You type the following command to proceed with MongoDB installation for CentOS 7 server.

In the demo, I am using CentOS version 7.6.1810 (Core) and the current MongoDB version is 4.0.9.

yum install -y mongodb-org

You can see more information about installation at the MongoDB tutorial page.

After installation is complete, type the following command to start the service.

service mongod start

Type below command to enable MongoDB’s service auto start after reboot.

chkconfig mongod on

And then, you check to see if the service is working.

service mongod status

The result like this.

[root@db01 ~]# service mongod status
Redirecting to /bin/systemctl status mongod.service
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-04-16 21:23:49 +07; 18h ago
  Process: 27437 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
  Process: 27435 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 27433 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 27431 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 27441 (mongod)
   CGroup: /system.slice/mongod.service
           └─27441 /usr/bin/mongod -f /etc/mongod.conf

Apr 16 21:23:48 db01 systemd[1]: Starting MongoDB Database Server...
Apr 16 21:23:48 db01 mongod[27437]: about to fork child process, waiting until server is ready for connections.
Apr 16 21:23:48 db01 mongod[27437]: forked process: 27441
Apr 16 21:23:49 db01 systemd[1]: Started MongoDB Database Server.

Like other databases, it also has shell cli for you to work with the database.

Type mongo to enter shell cli.

how-to-install-mongodb-in-centos-7 How to install MongoDB in CentOS 7
Use ‘mongo’ command to login MongoDB shell cli.


Installing MongoDB in CentOS 7 is really simple. In fact, it only takes about 2-3 lines of code to complete the installation. Yes, installation is one thing and using it is another.

If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.

Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.