MongoDB Iceberg : How to install MongoDB on Ubuntu Server?

ADDI Kamal
4 min readOct 28, 2021

Hello everyone, In this tutorial, you will install MongoDB on an Ubuntu 20.04 server, test it, and learn how to manage it as a systemd service.

Audience :

This tutorial is designed for Data Engineers, Software Professionals and anyone who wants to learn MongoDB Database in simple and easy steps. It will throw light on MongoDB concepts and after completing this tutorial you will be at an intermediate level of expertise, from where you can take yourself at a higher level of expertise.

Introduction :

MongoDB, also known as Mongo, is a high-performance, document-oriented database written in C++ and used in many modern web applications. It is classified as a NoSQL database because it does not rely on a traditional table-based relational database structure. Instead, it uses JSON-like documents with dynamic schemas, which means that, unlike relational databases, MongoDB does not require a predefined schema before adding data to a database. You can change the schema anytime and as often as needed without having to create a new database with an updated schema.

Preconditions :

To follow this tutorial, you will need :

  • An Ubuntu 20.04 server (in my case I use a virtual machine).
Ubuntu 20.04.3 LTS
  • MobaXterm client SSH (Toolbox for Remote Desktop using SSH Tunnel).

Note : MobaXterm is available on MCECS supported Windows machines and is available for personal machines here: https://mobaxterm.mobatek.net/download.html

MobaXterm

Step 1: Connecting to a Ubuntu server from Windows through MobaXterm

Open MobaxTerm. In the top left corner, select Sessions and select New session then select the SSH option as shown in the image below.

Connecting to a Remote Host from Windows through MobaXterm
  • In the Remote host section enter in the ip address of the computer you wish to access.
  • In the username section, put the username (in my case “kamal”).
  • Leave the Port section as the default 22 and click OK.

Step 2: Installing MongoDB

To install MongoDB on Ubuntu, follow these steps :

Run the following command to import the MongoDB public GPG key from https://www.mongodb.org/static/pgp/server-5.0.asc :

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

The operation should respond with an OK.

Create a /etc/apt/sources.list.d/mongodb-org-5.0.list file using the following command :

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

  • Reload local package database :

Issue the following command to reload the local package database :

sudo apt-get update

  • Install the MongoDB packages :

To install the latest stable version of MongoDB, issue the following

sudo apt-get install -y mongodb-org

Now MongoDB is installed successfully.

  • Start MongoDB :

You can start the mongod process by issuing the following command:

sudo systemctl start mongod

  • Verify that MongoDB has started successfully :

Then check the status of the service :

sudo systemctl status mongod

This command returns output similar to the following, indicating that the service is active:

After confirming that the service is working as expected, enable the MongoDB service by issuing the following command :

sudo systemctl enable mongod

  • Stop MongoDB :

As needed, you can stop the mongod process by issuing the following command :

sudo systemctl stop mongod

  • Restart MongoDB :

You can restart the mongod process by issuing the following command :

sudo systemctl restart mongod

  • Begin using MongoDB :

To use MongoDB run the following command :

mongo

Conclusion :

In this article, we connected to an ubuntu server using MobaXterm and installed the latest version of MongoDB, then we tested the functionality of Mongo and practiced some systemctl commands.

This quick introduction to MongoDB only covered the tip of the iceberg, we did not have the chance to discuss MongoDB usage and administration, but I leave that for another article!

Thank you for reading that far! I would be glad to hear your feedback 🤗.

Kamal ADDI

--

--

ADDI Kamal

Hi there, I’m Kamal, a data engineering student at the National Institute of Posts and Telecommunications. passionate about data science, big data, and IA.