# Installing DMK

This page describes how to install and configure DMK for the first time on a MongoDB server.

#### Unzipping DMK

Log in as the `mongodb` user using `su - mongodb`, and unzip DMK into the `/u01/app/mongodb/local` directory.

```bash
su - mongodb
unzip -oq dmk_mongodb-2.3.1.zip -d /u01/app/mongodb/local
```

#### Running `dmk.sh` for the first time

Then, source the `dmk.sh` script with `. /u01/app/mongodb/local/dmk/bin/dmk.sh` script to initialize the environment. It will create the basic configuration files.

{% hint style="warning" %}
**Warning** Be sure to run `. dmk.sh` (with a leading dot) rather than `dmk.sh` to ensure that environment variables are properly set in the current shell session.
{% endhint %}

```bash
[mongodb@vm00 ~]$ . /u01/app/mongodb/local/dmk/bin/dmk.sh
2025-12-04 10:03:48 | INFO | DMK_HOME environment variable is not defined.
2025-12-04 10:03:48 | INFO | First time installation of DMK.
2025-12-04 10:03:48 | INFO | DMK has been extracted to /u01/app/mongodb/local/dmk
2025-12-04 10:03:48 | INFO | Using DMK_HOME=/u01/app/mongodb/local/dmk
2025-12-04 10:03:48 | INFO | Default configuration file '/u01/app/mongodb/local/dmk/etc/dmk.conf.default' does not exist. Creating it.
2025-12-04 10:03:48 | INFO | Copying template file '/u01/app/mongodb/local/dmk/templates/etc/dmk.conf.unix' to '/u01/app/mongodb/local/dmk/etc/dmk.conf.default'
2025-12-04 10:03:48 | INFO | Local configuration file does not exist. Creating it.
2025-12-04 10:03:48 | INFO | Copying template file '/u01/app/mongodb/local/dmk/templates/etc/dmk.conf.local.template' to '/home/mongodb/.dmk/dmk.conf.local'
2025-12-04 10:03:48 | INFO | Creating symlink '/u01/app/mongodb/local/dmk/etc/dmk.conf.local' to '/home/mongodb/.dmk/dmk.conf.local'
2025-12-04 10:03:48 | WARNING | MONGO_BASE environment variable is not set. Trying to retrieve it from DMK_HOME (/u01/app/mongodb/local/dmk).
2025-12-04 10:03:48 | WARNING | MONGO_BASE set to '/u01/app/mongodb' based on DMK_HOME location.
2025-12-04 10:03:48 | WARNING | If you're running DMK for the first time, you can ignore these warnings.
2025-12-04 10:03:48 | WARNING | Otherwise, please set MONGO_BASE in /home/mongodb/.DMK before sourcing DMK.
2025-12-04 10:03:48 | WARNING | File '/u01/app/mongodb/etc/mongodb.lst' does not exist. Creating an empty file. If it's your first time running DMK, you can ignore this warning.
2025-12-04 10:03:48 | INFO | Creating DMK source file at '/home/mongodb/.DMK' with the following content:
2025-12-04 10:03:48 | INFO | DMK_HOME=/u01/app/mongodb/local/dmk
2025-12-04 10:03:48 | INFO | PYTHON_BIN=/usr/bin/python3
2025-12-04 10:03:48 | INFO | MONGO_BASE=/u01/app/mongodb
2025-12-04 10:03:48 | WARNING | Please make sure to source the .DMK file in your shell profile (e.g., .bash_profile).
2025-12-04 10:03:48 | WARNING | An example is provided at /u01/app/mongodb/local/dmk/templates/profile/dmk.mongodb.profile
```

After running this command, the DMK environment is loaded. In particular, an alias defined in `dmk.sh` allows you to reload the DMK environment at any time.

```bash
alias dmk='. ${DMK_HOME}/bin/dmk.sh'
```

For future use of the DMK, you can just load the environment with `dmk`.

Files created at this point are :

* `$MONGO_BASE/etc/mongodb.lst` : List of all MongoDB instances (empty at first).
* `$DMK_HOME/etc/dmk.conf.default` : Default configuration file for DMK. **Do not modify this file**, as it will be overwritten during DMK updates.
* `~/.dmk/dmk.conf.local` : Local configuration file for DMK. Changes made here overwrite default configuration.
* `~/.DMK` : File where `DMK_HOME` and the Python bin directory are defined. If your `MONGO_BASE` variable is different from `$DMK_HOME/../..`, then you should add a line to this file to specify your custom `MONGO_BASE` variable, and re-login to the `mongodb` user.

{% code title="\~/.DMK" overflow="wrap" lineNumbers="true" %}

```bash
export DMK_HOME=/u01/app/mongodb/local/dmk
export PYTHON_BIN=/usr/bin/python3
export MONGO_BASE=/u01/app/mongodb
```

{% endcode %}

If you have a custom Python installation that you want to use, please change the `PYTHON_BIN` variable.

If `MONGO_BASE` is not at the default OFA location, please change it.

#### Editing `.bash_profile`

Now, edit your `.bash_profile` file to add the function which will be used to source DMK environment at login, and to switch between instances. The template can be found under `/u01/app/mongodb/local/dmk/templates/profile/dmk.mongodb.profile`.

```bash
cp -p ${DMK_HOME}/templates/profile/dmk.mongodb.profile /home/mongodb/.bash_profile
```

This `.bash_profile` will load DMK at login.

{% code title=".bash\_profile" overflow="wrap" lineNumbers="true" %}

```bash
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs
umask 022

# BEGIN DMK BLOCK
if [ -z "$DMK_HOME" ]; then
    if [ -f "$HOME/.DMK" ]; then
        . "$HOME/.DMK"
    else
        echo "$HOME/.DMK file does not exist. It is needed to source DMK at login. Run '. <DMK_HOME>/bin/dmk.sh' or 'source <DMK_HOME>/bin/dmk.sh' to source DMK manually this time."
        return 1
    fi
fi

# Launched at login
. $DMK_HOME/bin/dmk.sh && $PYTHON_BIN $DMK_HOME/bin/dmk_status.py --table --all
# END DMK BLOCK
```

{% endcode %}

You can source `.bash_profile` to verify that the DMK environment is correctly loaded:

```bash
[mongodb@vm00 ~]$ . .bash_profile
2025-06-27 11:09:48 | INFO     | No MongoDB instances found.
```

{% hint style="success" %}
You have successfully completed the DMK installation process.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dbi-services.gitbook.io/dmk-mongodb/installation-and-setup/installing_dmk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
