How to install MongoDB 4.2 – CentOS 7, Ubuntu 18.04 LTS and Ubuntu 19.04

 

Today we’ll be looking at how to install MongoDB 4.2 on CentOS 7, Ubuntu 18.04 LTS and Ubuntu 19.04

A little bit about MongoDB as per their website:

Before you set off you need to make sure you’re either logged in as root or a user with sudo privileges

Installation on CentOS 7

Add the MongoDB 4.2 repository

Create a new file at /etc/yum.repos.d/mongodb-4.2.repo and paste the following into the file:

Install MongoDB

Issue the following to install MongoDB onto the server:

This will install the following packages and dependencies:

Start the service

To start the MongoDB service issue the following:

Add MongoDB to startup

To start MongoDB on server boot issue the following:

Verify the installation

To verify the installation, issue the following at the terminal:

The server should return something like the following:

Start using MongoDB

Start a mongo shell and start using it on the server:


Installation on Ubuntu 18.04 LTS and Ubuntu 19.04

Import the public key

Issue the following at the terminal to import the MongoDB public GPG key:

Create a list file for MongoDB

Issue the following to create a list file for MongoDB:

Reload the local package database

Issue the following to reload the local package database of Ubuntu:

Install the MongoDB

Issue the following to install MongoDB server and it’s dependencies

This will install the following packages and it’s dependencies:

Start the service

Issue the following to start the MongoDB service:

Verify the installation

To verify the installation, issue the following:

Start using MongoDB

Start a mongo shell and start using it on the server:

That’s it, you’re done!