How to Install MongoDB on VPS

What is MongoDB?

Have you ever heard of MongoDB and how to install MongoDB on a VPS? If you are a developer, you must be familiar with the name MongoDB. Yes, MongoDB is a  cross-platform document-oriented database, which is different from relational database management system (RDBMS)  such as MySQL . MongoDB is included in one of the NoSQL (Not Only SQL) databases where the data stored in the MongoDB database will be in BSON format.

How to Install MongoDB on VPS

After understanding a brief explanation of what MongoDB is before, then how to install MongoDB on a VPS / Server?. Here are the steps to install MongoDB on VPS/Server.

1. Adding the MongoDB repository

Before installing the MongoDB package you need to add the MongoDB repository first. Because by default the MongoDB repository is not yet in the repository list on your VPS / Server. To add the repository, please follow the following command:


yum install -y vim wget curl
vim /etc/yum.repos.d/mongodb.repo

Please add the following repository:

name=MongoDB Repository

To check whether the MongoDB repository has been added to the repository list, you can check with the command :

yum repolist

And then the results will appear more or less like the following:

# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * updates:
repo id                                 repo name                                                              status
MongoDB/7                               MongoDB Repository                                                         55
base/7/x86_64                           CentOS-7 - Base                                                        10,019
epel/x86_64                             Extra Packages for Enterprise Linux 7 - x86_64                         13,242
extras/7/x86_64                         CentOS-7 - Extras                                                         419
updates/7/x86_64                        CentOS-7 - Updates                                                      2,137
repolist: 25,872


apt-key adv --keyserver hkp:// --recv 68818C72E52529D4

echo "deb bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

And then the results will appear more or less like the following:

apt-get update

2. Install MongoDB

After adding the MongoDB repository, then you can install the MongoDB packages with the following command:


yum install -y mongodb-org


apt install -u mongodb-org

Wait a few moments for the installation process to complete.

3. Start service MongoDB

When the installation process is complete, usually the service for MongoDB Server is not yet running. And to run the service you need to run the following command:


systemctl enable mongod
systemctl start mongod


service start mongod

4. Testing

To see if MongoDB is installed properly, we can test by checking the version of MongoDB installed with the following command:

mongod --version

And then the results will appear more or less like the following:

# mongod --version
db version v4.0.10
git version: c389e7f69f637f7a1ac3cc9fae843b635f20b766
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64


MongoDB is a NoSQL database that is an alternative for developers in developing applications that apply Big Data where the stored data tables are not bound by relationships such as those in the Relational Database Management System (RDBMS) , so that the database in MongoDB is flexible and easy to develop again (scalability).

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.