Press Ctrl/Cmd + P to print
or save as PDF

Installing MongoDB for Linux Based VPS in 3 Simple Steps

MongoDB is one of the most well-known NoSQL database managers. MongoDB is used for saving documents instead of data record such as SQL and applications that save data in formatted documents relies on it. MongoDB is also popular in environments that require a lot of scalabilities. You can quickly conduct replication procedures using MongoDB, allowing data scalability. MongoDB can be used by any application that needs to store semi-structured data.

In this article, we will be guiding you on how to install MongoDB in your Linux based VPS. The Linux distribution used in this tutorial is Ubuntu version 18.04.

Step 1: Connect Server With SSH

First and foremost, connect to the server using SSH. Make sure you have the sudo privilege within the server as well.

ssh <user_name>@<server_name>

Replace “<user_name>” and “<server_name>” with your own username and the name of the server respectively.

Step 2: Add MongoDB repository

To avoid compromising downloaded packages, add the PGP key from the MongoDB repository.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

After adding the PGP key, run the following command to install the MongoDB repository.

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Next, update all the repositories using the following command.

sudo apt update

Step 3: Installation

To install MongoDB into your VPS, run the following commands.

sudo apt-get install -y mongodb
sudo apt install mongodb-org

After finishing installing MongoDB, you may start it using the start command as followed.

sudo systemctl start mongodb

To start MongoDB on every system boot, use the following command.

sudo systemctl enable mongodb

Finally, to check the status of MongoDB, run the following command.

sudo systemctl status mongodb

You have completed installing MongoDB into your system. Retrace the previous steps if there are any issues with the installation.