How to Install and Configure MongoDB on Ubuntu 22.04?


Share:
 | Published By: Admin | Published On: Jun 25, 2022 | Category: Ubuntu

Hi Guys

This article will give you example of Install MongoDB Enterprise Edition on Ubuntu 22.04. you'll learn Which Command Install MongoDB on a Ubuntu System Via Package Manager?. you will learn Where does MongoDB install on Ubuntu?. you can see Errors when Installing MongoDB on Ubuntu 22.04.

You can use this post for ubuntu 14.04, ubuntu 16.04, ubuntu 18.4, ubuntu 20.04, ubuntu 21 and ubuntu 22.04 versions.

Use the following steps to install

(1). Install the dependencies

(2). Import the repository’s GPG key

(3). Install MongoDB

(4). Configuring MongoDB

(5). Creating Administrative MongoDB User

(6). Restart Server

Step 1: Install the dependencies

To install the dependencies you need to add a new repository over HTTPS

sudo apt update
sudo apt install dirmngr gnupg apt-transport-https ca-certificates 
software-properties-common
Step 2: Import the repository’s GPG key

Type the following command to import the GPG key of the repository and add the Mongodibi repository.

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-
key add -
sudo add-apt-repository 'deb [arch=amd64] 
https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse'
Step 3: Install MongoDB

execute the following command on your terminal to install mongodb:

sudo apt install mongodb-org

Then run the following command on the terminal to start the MongoDB daemon

sudo systemctl enable --now mongod
Step 4: Configuring MongoDB

Reopen your terminal and run the following command to configure mongodb in the mongod.conf file:

sudo nano /etc/mongod.conf

After that, add the following line into mongod.conf file and save it:

security:
   authorization: enabled

Restart the Mongodb service to edit:

Step 5: Creating Administrative MongoDB User

You will need to create an administrative user who can access and manage the Mongodib instance. So run the following command on it:

mongo

Then type this following query:

use admin

The output will be:

switched to db admin

Now, execute the following command to create a new user named mongoAdmin, with password changeMe and userAdminAnyDatabase role:

db.createUser(
    {
        user: "mongoAdmin",
        pwd: "changeMe",
        roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
    }
)

Then, get out of Mongo Shell:

quit() 
Step 6: Restart Server

After installing Mongodb and configure it on Ubuntu 22.04

sudo systemctl restart mongod
Share: