How to Install MongoDB on CentOS 7
In this MongoDB tutorial we are going to see how to install NoSQL Database MongoDB on CentOS 7.
MongoDB is not available from the official CentOS 7 software repository, But MongoDB provides a yum repository for CentOS 7 which we use to install the latest version of MongoDB on CentOS 7.
Following are the steps you need to follow.
- Add MongoDB repository for CentOS 7.
- Install MongoDB with yum install command.
- Start mongod service with systemctl command.
Add MongoDB repository for CentOS 7
Let's start with creating the yum repository for MongoDB Database Server.
Create yum repo file:
Then, open the mongodb-org-3.4.repo file with your preferred text editor and add following entries.
[mongodb-org-3.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
Run the yum repolist command and make sure mongodb repository is active.
Install MongoDB with yum install command
Now the repository is set, We can install mongodb with yum install command:
sudo yum -y install mongodb-org
The mongodb-org package also includes following core packages, mongodb-org-server, mongodb-org-shell and mongodb-org-tools.
Start mongod service with systemctl command
After the installation is finished, Start the mongod.service with systemctl command:
sudo systemctl start mongod.service
Also set mongod.service to start at system reboot:
sudo systemctl enable mongod.service
To view the server version, Type:
To view the server status, Type:
systemctl status mongod.service
MongoDB Shell on CentOS 7
Just like MySQL, MongoDB also includes command line interface to manage DB Server. We can get access to the mongo shell with the mongo command.
For command help, Type:
To exit mongo shell, Type:
In this tutorial we learned How to install MongoDB on CentOS 7. First, we created the yum repository. Then we install MongoDB with yum command.