Setup MongoDB in Kali Linux

Naresh Kumar
3 min readFeb 28, 2020

--

1. Import the public key used by the package management system

To setup MongoDB in kali linux or in any other debian flavor we will have to import the publig GPG key.

wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
Importing Public Key

However, if you receive an error indicating that gnupg is not installed, you can:

  1. Install gnupg and its required libraries using the following command:
sudo apt-get install gnupg
  1. Once installed, retry importing the key:
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

2. Create a /etc/apt/sources.list.d/mongodb-org-4.2.list file for MongoDB

Create the list file using the command appropriate for your version of Debian:

Here we will be create .list for Debian 10 “Buster”

echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
Create .list for the MongoDB

3. Reload local package database

Issue the following command to reload the local package database:

sudo apt-get update

4. Install the MongoDB packages

You can install either the latest stable version of MongoDB or a specific version of MongoDB.

sudo apt-get install -y mongodb-org

To install a specific release, you must specify each component package individually along with the version number, as in the following example:

sudo apt-get install -y mongodb-org=4.2.3 mongodb-org-server=4.2.3 mongodb-org-shell=4.2.3 mongodb-org-mongos=4.2.3 mongodb-org-tools=4.2.3

Start MongoDB

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

sudo systemctl start mongod

If you receive an error similar to the following when starting mongod:

Failed to start mongod.service: Unit mongod.service not found.

Run the following command first:

sudo systemctl daemon-reload

Then run the start command above again.

Verify that the MongoDB has started

sudo systemctl status mongod

You can optionally ensure that MongoDB will start following a system reboot 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

mongo

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Naresh Kumar
Naresh Kumar

Written by Naresh Kumar

Security Analyst making safe cyberspace 4 people #cyber4people India

Responses (6)

Write a response