How to Install MongoDB on Your CentOS 7 VPS or Dedicated Server

MongoDB is designed for extensive databases and is mainly used for data analytics, Big data, and gaming among others. In case you are in those industries and would like to scale your database, then MongoDB is what you need.

In this article, we document the step by step instructions on how to install MongoDB on a Linux VPS box running CentOS 7.

Overview

MongoDB is one of the leading in the market of the NoSQL database. It is an open source document-oriented database. It boasts of an enormous number of users all around the world. Thanks to its data integrity as well as its integration with popular programming languages, one can see why it has such a large following (visit our best MongoDB Hosting services for a list of the best MongoDB hosts). So let’s see how to install it on our CentOS 7 Virtual private server (VPS).

Installing MongoDB

Adding the MongoDB repository

MongoDB maintains a dedicated repository. So, to add it to our server we are going to use the vi editor to create a repo file for yum. Type the following command.

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

Next, open a new file and add the repository information for the latest release of the file;

/etc/yum.repos.d/mongodb-org.repo

[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

Next, save your changes and close the file. If you wish to verify that the MongoDB repository exists, you can do so by typing the repolist command. This command lists enabled directories;

$ yum repolist

You should see the following:

Now that you have installed the MongoDB repository, you are now ready to install MongoDB.

Install MongoDB from the repository.

We are going to get the mongodb-org from a different repository using the yum command,

$ sudo yum install mongodb-org

Some prompts will appear, the first one will permit the installation of MongoDB packages, and the next one will import a GPG key. Accepting both the prompts is essential. Type Y at each prompt and then press enter.

Your installation is now complete.

Starting MongoDB

To start the mongod process, type;

$ sudo systemctl start mongod

You can also change the state of the MongoDB service with the reload command which requests the process to read the configuration file and save changes without requiring a restart, or the stop command. The stop command stops all running mongod processes.

That is it, now to verify if MongoDB started, you can check the end of the mongod.log file by using the tail command;

$ sudo tail /var/log/mongodb/mongod.log

The output should look like the following:

If it shows the above statement, it means that MongoDB has successfully started and we can now access the database server by typing;

$ mongo

Verifying Startup

Use the systemctl command to check its status

$ systemctl is-enabled mongod; echo $?

If it returns a zero, it means that the daemon is enabled.

If for some reason it returns a one, use the systemctl utility to enable the daemon/process.

$ sudo systemctl enable mongod

Conclusion

Not to forget its powerful management service that allows users to track databases and the data back-up machines. This not only helps in streamlining processes and procedures but also making sure your data integrity is kept in check. Installing MongoDB on a CentOS VPS is similar to installation on normal CentOS 7 server.

 

Check out the top 3 Dedicated server hosting services:

HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
Kamatera
$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
A2 Hosting
$2.99 /mo
Starting price
Visit A2 Hosting
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0

Installing MongoDB on Ubuntu 22.04 – A Complete Guide

This tutorial will help you install and configure MongoDB 5.0.9 on your Ubuntu 2
7 min read
Bruno Mirchevski
Bruno Mirchevski
Hosting Expert

How to Install the MEAN Stack on Your CentOS 7 VPS or Dedicated Server

This how-to article will show you how to install the MEAN (MongoDB, Express, Ang
2 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Install the MEAN Stack on Your Ubuntu 17.10 Server

The article is step-to-step instruction that shows how to install the MEAN (Mong
3 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Install Redis on a CentOS 7 Server

This tutorial provides a step-by-step guide for installing, configuring, managin
5 min read
Idan Cohen
Idan Cohen
Marketing Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.