Lagos, Nigeria

How to install the NoSQL database server MongoDB on Linux

Jack Wallen walks you through the process of installing the MongoDB NoSQL database server on both Ubuntu Server and AlmaLinux.


Image: Jack Wallen

MongoDB is a cross-platform, document-oriented database that is classified in the NoSQL family. That means it’s human-readable and scalable to meet the high demands of enterprise businesses. MongoDB works on all types of computing platforms, whether they be cloud-hosted or on-premises, and can serve as the backend for numerous use-cases.

I’ve covered the installation of MongoDB for Ubuntu Server 16.04 (see: How to install MongoDB community edition on Ubuntu Linux), but the process has changed since 2016. This time around we’re going to install MongoDB Community Edition on both Ubuntu Server 20.04 and AlmaLinux (the CentOS fork). In an upcoming piece, I’ll show you how to then create a MongoDB cluster.

SEE: Linux service control commands (TechRepublic Premium)

What you’ll need

To get MongoDB installed, you’ll need a running, updated instance of either Ubuntu Server 20.04 or AlmaLinux. You’ll also need a user with sudo privileges.

Note: The official (and initial) release of AlmaLinux isn’t until March 30, 2021. If you want to test this process, you can download the beta release or migrate a running instance of CentOS 8 to AlmaLinux (see: How to migrate CentOS to AlmaLinux and avoid downtime in your data center). 

How to install MongoDB on Ubuntu Server 20.04

The first thing we must do is import the MongoDB GPG key onto the server. To do that, log in to your Ubuntu instance and issue the command:

wget -qO - | sudo apt-key add -

Once the key is added, we then must create a new apt list file for MongoDB. Issue the command:

sudo nano /etc/apt/sources.list.d/mongodb-org-4.4.list

In that file, paste the following contents:

deb [ arch=amd64,arm64 ] focal/mongodb-org/4.4 multiverse

Save and close the file. 

Update the apt database with the command:

sudo apt-get update

After apt completes the update process, you can install the latest version of MongoDB with the command:

sudo apt-get install -y mongodb-org

When the installation finishes, start and enable the MongoDB service with the commands:

sudo systemctl start mongod 
sudo systemctl enable mongod

You can now launch the MongoDB shell with the command:


How to install MongoDB on AlmaLinux

Let’s head over to AlmaLinux for the installation. Log in to that instance and create a new yum repo file with the command:

sudo nano /etc/yum.repos.d/mongodb-org-4.4.repo

In that file, paste the following:

name=MongoDB Repository

Save and close the file.

Install MongoDB with the command:

sudo dnf mongodb-org -y

After the installation completes, start and enable the service with the commands:

sudo systemctl start mongod
sudo systemctl enable mongod

Like with Ubuntu, to access the MongoDB shell, issue the command:


And that’s all there is to installing MongoDB on both Ubuntu Server and AlmaLinux. These steps can be used for nearly any Debian- or Red Hat-based Linux distributions. 

Next time around we’ll take a look at how to create a small cluster of MongoDB servers.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Also see

This post was written by and was first posted to TechRepublic

Do you find this article helpful? Your Friend might too. So, please Share it with them using the Share button above.
Will you like to get notified when I post new updates? Then Follow me on any of my social media handles: Google News, Telegram, WhatsApp, Twitter, Facebook, Pinterest.
You can also drop your email address below if you wish to be notified by mail.

Tags: ,

%d bloggers like this: