Cyber4People
Published in

Cyber4People

Setup MongoDB in Kali Linux

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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store