How to Install MongoDB 4.0 on Centos 7/RHEL 7

In this tutorial we’ll  Install MongoDB 4.0 on Centos 7/RHEL 7 linux OS. MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. it is recommended for business and enterprise uses although you can also use in your production environment. It is a NoSQL database. MongoDB 4.0 supports multi-document ACID transactions.

Step 1

Adding MongoDB 4.0 Repository  :

Create repo file :

yum install nano -y
nano /etc/yum.repos.d/mongodb4.repo

Now add this lines to mongodb4.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

Save and exit

Step 2

Installing MongoDB 4.0 :

yum install -y mongodb-org

If you’ve enabled selinux you need to run this command in order to give access :

semanage port -a -t mongod_port_t -p tcp 27017

*use this command if you’re using enforcing mode

Step 3

Verify the installation and enable startup :

Start MongoDB Service :

service mongod start

To restart and stop MongoDB Service :

service mongod restart
service mongod stop

you need to run this command from command line in order to access mongo db CLI interface :

mongo

To enable mogodb start automatically during os boot :

systemctl enable mongod
Back to top button