---
isPrivate: true
title: Install Datadog Agent 5
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > Agent > Agent Guides > Install Datadog Agent 5
---

# Install Datadog Agent 5

This guide covers installing Agent 5. Datadog recommends installing or upgrading to Agent 7 for the latest features. For information on installing the latest version of the Agent, follow the [Agent 7 Installation Instructions](https://app.datadoghq.com/account/settings/agent/latest?platform=overview). For information on upgrading to Agent 7 from an earlier version, see [Upgrade to Datadog Agent v7](https://docs.datadoghq.com/agent/versions/upgrade_to_agent_v7/).

## macOS{% #macos %}

### Install the Agent{% #install-the-agent %}

#### Command line{% #command-line %}

Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
DD_API_KEY=MY_API_KEY bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/osx/install.sh)"
```



To manage the Agent, use the `datadog-agent` command. By default, the `datadog-agent` binary is located in `/usr/local/bin`. Enable or disable integrations in `/opt/datadog-agent/etc/conf.d`.

#### GUI{% #gui %}

1. Download and install the [DMG package](https://install.datadoghq.com/datadog-agent-5.11.3-1.dmg).
1. Add the following line to `/opt/datadog-agent/etc/datadog.conf`, replacing `MY_API_KEY` with your Datadog API key:
   ```shell
   api_key:MY_API_KEY
```

To manage the Agent, use the Datadog Agent app in the system tray. Enable or disable integrations in `/opt/datadog-agent/etc/conf.d`.

### Agent run behavior{% #agent-run-behavior %}

By default, the Agent runs at login. You can disable it using the Datadog Agent app in the system tray. If you want to run the Agent at boot, use these commands:

```shell
sudo cp '/opt/datadog-agent/etc/com.datadoghq.agent.plist' /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/com.datadoghq.agent.plist
```



### Uninstall{% #uninstall %}

1. Stop and close the Datadog Agent with the bone icon in the tray.

1. Drag the Datadog application from the application folder to the trash bin.

1. Run:

   ```shell
   sudo rm -rf /opt/datadog-agent
   sudo rm -rf /usr/local/bin/datadog-agent
   sudo rm -rf ~/.datadog-agent/** # to remove broken symlinks
   ```

If you ran the optional install commands to have the Agent run at boot time, run the following to finish uninstalling:

```shell
sudo launchctl unload -w /Library/LaunchDaemons/com.datadoghq.agent.plist
sudo rm /Library/LaunchDaemons/com.datadoghq.agent.plist
```

## Windows{% #windows %}

### Install the Agent{% #install-the-agent-1 %}

#### GUI{% #gui-1 %}

Download and run the Datadog Agent installer:

- [64-bit installer](https://s3.amazonaws.com/ddagent-windows-stable/ddagent-cli-latest.msi).
- [32-bit installer](https://s3.amazonaws.com/ddagent-windows-stable/ddagent-32bit-cli.msi). 32-bit installations are only supported up to Agent version 5.10.1.

Links to all available versions of the Windows installer are available in [JSON format](https://s3.amazonaws.com/ddagent-windows-stable/installers.json).

#### Command line{% #command-line-1 %}

1. Download the Agent:
   - For fresh installations, download the [Datadog Agent installer](https://s3.amazonaws.com/ddagent-windows-stable/ddagent-cli-latest.msi).
   - If you're upgrading from a Datadog Agent version <5.12.0, use the [EXE installation method](https://s3.amazonaws.com/ddagent-windows-stable/ddagent-cli-latest.exe).
1. In a `cmd.exe` shell in the directory where you downloaded the installer, run the following command. Replace `MY_API_KEY` with your Datadog API key:
   ```shell
   start /wait msiexec /qn /i ddagent-cli-latest.msi APIKEY="MY_API_KEY"
```
Optionally, add `TAG` and `HOSTNAME` values.

#### Deployment to Azure{% #deployment-to-azure %}

To install the Agent on Azure, follow the [Microsoft Azure documentation](https://docs.datadoghq.com/integrations/azure/).

### New upgrade procedure for 5.12{% #new-upgrade-procedure-for-512 %}

If you are an existing customer running a Windows Agent prior to 5.12, there may be additional steps required to upgrade your device. Specifically, the latest Agent is a "per-machine" installation. Prior versions of the Agent were "per-user" by default. There may also be additional steps required if you're deploying with Chef. For more information, see [Windows Agent Installation](https://github.com/DataDog/dd-agent/wiki/Windows-Agent-Installation).

### Uninstall{% #uninstall-1 %}

There are two different methods to uninstall the Agent on Windows. Both methods remove the Agent, but do not remove the `C:\ProgramData\Datadog` configuration folder on the host.

**Note**: For Agent < v5.12.0, it's important to uninstall the Agent with the **original account** used to install the Agent, otherwise it may not be cleanly removed.

### Add or remove programs{% #add-or-remove-programs %}

1. Press **CTRL** and **Esc** or use the Windows key to run Windows Search.
1. Search for `add` and click **Add or remove programs**.
1. Search for `Datadog Agent` and click **Uninstall**.

### PowerShell{% #powershell %}

**Note:** Enable WinRM to use the commands below.

Use the following PowerShell command to uninstall the Agent without rebooting:

```powershell
start-process msiexec -Wait -ArgumentList ('/log', 'C:\uninst.log', '/norestart', '/q', '/x', (Get-CimInstance -ClassName Win32_Product -Filter "Name='Datadog Agent'" -ComputerName .).IdentifyingNumber)
```

## Linux and Unix{% #linux-and-unix %}

{% tab title="Debian" %}
### One-step install{% #one-step-install %}

The one-step command installs the APT packages for the Datadog Agent and prompts you for your password. If the Agent is not already installed on your machine and you don't want it to start automatically after the installation, prepend `DD_INSTALL_ONLY=true` to the command before running it.

Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
DD_API_KEY=MY_API_KEY bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/install_agent.sh)"
```

### Multi-step install{% #multi-step-install %}

1. Set up APT so it can download through HTTPS and install `curl` and `gnupg`:

   ```shell
   sudo apt-get update
   sudo apt-get install apt-transport-https curl gnupg
   ```

1. Set up the Datadog Debian repo on your system and create a Datadog archive keyring:

   ```shell
   sudo sh -c "echo 'deb [signed-by=/usr/share/keyrings/datadog-archive-keyring.gpg] https://apt.datadoghq.com/ stable main' > /etc/apt/sources.list.d/datadog.list"
   sudo touch /usr/share/keyrings/datadog-archive-keyring.gpg
   sudo chmod a+r /usr/share/keyrings/datadog-archive-keyring.gpg
   
   curl https://keys.datadoghq.com/DATADOG_APT_KEY_CURRENT.public | sudo gpg --no-default-keyring --keyring /usr/share/keyrings/datadog-archive-keyring.gpg --import --batch
   curl https://keys.datadoghq.com/DATADOG_APT_KEY_06462314.public | sudo gpg --no-default-keyring --keyring /usr/share/keyrings/datadog-archive-keyring.gpg --import --batch
   curl https://keys.datadoghq.com/DATADOG_APT_KEY_C0962C7D.public | sudo gpg --no-default-keyring --keyring /usr/share/keyrings/datadog-archive-keyring.gpg --import --batch
   curl https://keys.datadoghq.com/DATADOG_APT_KEY_F14F620E.public | sudo gpg --no-default-keyring --keyring /usr/share/keyrings/datadog-archive-keyring.gpg --import --batch
   curl https://keys.datadoghq.com/DATADOG_APT_KEY_382E94DE.public | sudo gpg --no-default-keyring --keyring /usr/share/keyrings/datadog-archive-keyring.gpg --import --batch
   ```

1. If running Debian 8 or earlier, copy the keyring to `/etc/apt/trusted.gpg.d`:

   ```shell
   sudo cp -a /usr/share/keyrings/datadog-archive-keyring.gpg /etc/apt/trusted.gpg.d/
   ```

1. Update your local APT repo and install the Agent:

   ```shell
   sudo apt-get update
   sudo apt-get install datadog-agent datadog-signing-keys
   ```

1. Run the following command to copy the example config into place. Replace `MY_API_KEY` with your Datadog API key:

   ```shell
   sudo sh -c "sed 's/api_key:.*/api_key:MY_API_KEY /' /etc/dd-agent/datadog.conf.example > /etc/dd-agent/datadog.conf"
   ```

1. Start the Agent:

   ```shell
   sudo /etc/init.d/datadog-agent start
   ```

{% /tab %}

{% tab title="Ubuntu" %}
### One-step install{% #one-step-install %}

The one-step command installs the APT packages for the Datadog Agent and prompts you for your password. If the Agent is not already installed on your machine and you don't want it to start automatically after the installation, prepend `DD_INSTALL_ONLY=true` to the command before running it.

Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
DD_API_KEY=MY_API_KEY bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/install_agent.sh)"
```

### Multi-step install{% #multi-step-install %}

1. Set up APT so it can download through HTTPS and install `curl` and `gnupg`:

   ```shell
   sudo apt-get update
   sudo apt-get install apt-transport-https curl gnupg
   ```

1. Set up the Datadog Debian repo on your system and create a Datadog archive keyring:

   ```shell
   sudo sh -c "echo 'deb [signed-by=/usr/share/keyrings/datadog-archive-keyring.gpg] https://apt.datadoghq.com/ stable main' > /etc/apt/sources.list.d/datadog.list"
   sudo touch /usr/share/keyrings/datadog-archive-keyring.gpg
   sudo chmod a+r /usr/share/keyrings/datadog-archive-keyring.gpg
   
   curl https://keys.datadoghq.com/DATADOG_APT_KEY_CURRENT.public | sudo gpg --no-default-keyring --keyring /usr/share/keyrings/datadog-archive-keyring.gpg --import --batch
   curl https://keys.datadoghq.com/DATADOG_APT_KEY_06462314.public | sudo gpg --no-default-keyring --keyring /usr/share/keyrings/datadog-archive-keyring.gpg --import --batch
   curl https://keys.datadoghq.com/DATADOG_APT_KEY_C0962C7D.public | sudo gpg --no-default-keyring --keyring /usr/share/keyrings/datadog-archive-keyring.gpg --import --batch
   curl https://keys.datadoghq.com/DATADOG_APT_KEY_F14F620E.public | sudo gpg --no-default-keyring --keyring /usr/share/keyrings/datadog-archive-keyring.gpg --import --batch
   curl https://keys.datadoghq.com/DATADOG_APT_KEY_382E94DE.public | sudo gpg --no-default-keyring --keyring /usr/share/keyrings/datadog-archive-keyring.gpg --import --batch
   ```

1. If running Debian 8 or earlier, copy the keyring to `/etc/apt/trusted.gpg.d`:

   ```shell
   sudo cp -a /usr/share/keyrings/datadog-archive-keyring.gpg /etc/apt/trusted.gpg.d/
   ```

1. Update your local APT repo and install the Agent:

   ```shell
   sudo apt-get update
   sudo apt-get install datadog-agent datadog-signing-keys
   ```

1. Run the following command to copy the example config into place. Replace `MY_API_KEY` with your Datadog API key:

   ```shell
   sudo sh -c "sed 's/api_key:.*/api_key:MY_API_KEY /' /etc/dd-agent/datadog.conf.example > /etc/dd-agent/datadog.conf"
   ```

1. Start the Agent:

   ```shell
   sudo /etc/init.d/datadog-agent start
   ```

### Uninstall{% #uninstall %}

To uninstall the Agent, run the following command:

```shell
sudo apt-get remove datadog-agent -y
```

This command removes the Agent, but does not remove:

- The `datadog.yaml` configuration file
- User-created files in the `/etc/dd-agent` configuration folder
- User-created files in the `/opt/datadog-agent` folder
- The `dd-agent` user
- Datadog log files

If you also want to remove these elements, run this command after removing the Agent:

```shell
sudo apt-get --purge remove datadog-agent -y
```

{% /tab %}

{% tab title="Amazon Linux" %}
### One-step install{% #one-step-install %}

The one-step command installs the YUM packages for the Datadog Agent and prompts you for your password. If the Agent is not already installed on your machine and you don't want it to start automatically after the installation, prepend `DD_INSTALL_ONLY=true` to the command before running it.

Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
DD_API_KEY=MY_API_KEY bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/install_agent.sh)"
```

### Multi-step install{% #multi-step-install %}

1. Set up the Datadog YUM repo by creating `/etc/yum.repos.d/datadog.repo` with the following contents:

   ```
   [datadog]
   name=Datadog, Inc.
   baseurl=https://yum.datadoghq.com/rpm/x86_64/
   enabled=1
   gpgcheck=1
   gpgkey=https://keys.datadoghq.com/DATADOG_RPM_KEY_CURRENT.public
          https://keys.datadoghq.com/DATADOG_RPM_KEY_B01082D3.public
          https://keys.datadoghq.com/DATADOG_RPM_KEY_FD4BF915.public
   ```

**Note**: On i386/i686 architecture, replace "x86_64" with "i386".

1. Update your local yum repo and install the Agent:

   ```shell
   sudo yum makecache
   sudo yum install datadog-agent
   ```

1. Copy the example config into place. Replace `MY_API_KEY` with your Datadog API key:

   ```shell
   sudo sh -c "sed 's/api_key:.*/api_key:MY_API_KEY /' /etc/dd-agent/datadog.conf.example > /etc/dd-agent/datadog.conf"
   ```

1. Restart the Agent:

   ```shell
   sudo /etc/init.d/datadog-agent restart
   ```

### Uninstall{% #uninstall %}

To uninstall the Agent, run the following command:

```shell
sudo yum remove datadog-agent
```

This command removes the Agent, but does not remove:

- The `datadog.yaml` configuration file
- User-created files in the `/etc/dd-agent` configuration folder
- User-created files in the `/opt/datadog-agent` folder
- The `dd-agent` user
- Datadog log files

If you also want to remove these elements, run this command after removing the Agent:

```shell
sudo userdel dd-agent \
&& sudo rm -rf /opt/datadog-agent/ \
&& sudo rm -rf /etc/dd-agent/ \
&& sudo rm -rf /var/log/datadog/
```

{% /tab %}

{% tab title="CentOS and Red Hat" %}
### One-step install{% #one-step-install %}

The one-step command installs the YUM packages for the Datadog Agent and prompts you for your password. If the Agent is not already installed on your machine and you don't want it to start automatically after the installation, prepend `DD_INSTALL_ONLY=true` to the command before running it.

Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
DD_API_KEY=MY_API_KEY bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/install_agent.sh)"
```

### Multi-step install{% #multi-step-install %}

1. Set up the Datadog YUM repo by creating `/etc/yum.repos.d/datadog.repo` with the following contents:

   ```
   [datadog]
   name=Datadog, Inc.
   baseurl=https://yum.datadoghq.com/rpm/x86_64/
   enabled=1
   gpgcheck=1
   gpgkey=https://keys.datadoghq.com/DATADOG_RPM_KEY_CURRENT.public
          https://keys.datadoghq.com/DATADOG_RPM_KEY_B01082D3.public
          https://keys.datadoghq.com/DATADOG_RPM_KEY_FD4BF915.public
   ```

**Note**: On i386/i686 architecture, replace "x86_64" with "i386".

1. Update your local YUM repo and install the Agent:

   ```shell
   sudo yum makecache
   sudo yum remove datadog-agent-base 
   sudo yum install datadog-agent
   ```

1. Copy the example config into place. Replace `MY_API_KEY` with your Datadog API key:

   ```shell
   sudo sh -c "sed 's/api_key:.*/api_key:MY_API_KEY /' /etc/dd-agent/datadog.conf.example > /etc/dd-agent/datadog.conf"
   ```

1. Restart the Agent:

   ```shell
   sudo /etc/init.d/datadog-agent restart
   ```

### Uninstall{% #uninstall %}

To uninstall the Agent, run the following command:

```shell
sudo yum remove datadog-agent
```

This command removes the Agent, but does not remove:

- The `datadog.yaml` configuration file
- User-created files in the `/etc/dd-agent` configuration folder
- User-created files in the `/opt/datadog-agent` folder
- The `dd-agent` user
- Datadog log files

If you also want to remove these elements, run this command after removing the Agent:

```shell
sudo userdel dd-agent \
&& sudo rm -rf /opt/datadog-agent/ \
&& sudo rm -rf /etc/dd-agent/ \
&& sudo rm -rf /var/log/datadog/
```

{% /tab %}

{% tab title="Fedora" %}
### One-step install{% #one-step-install %}

The one-step command installs the YUM packages for the Datadog Agent and prompts you for your password. If the Agent is not already installed on your machine and you don't want it to start automatically after the installation, prepend `DD_INSTALL_ONLY=true` to the command before running it.

Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
DD_API_KEY=MY_API_KEY bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/install_agent.sh)"
```

### Multi-step install{% #multi-step-install %}

1. Set up the Datadog YUM repo by creating `/etc/yum.repos.d/datadog.repo` with the following contents:

   ```
   [datadog]
   name=Datadog, Inc.
   baseurl=https://yum.datadoghq.com/rpm/x86_64/
   enabled=1
   gpgcheck=1
   gpgkey=https://keys.datadoghq.com/DATADOG_RPM_KEY_CURRENT.public
          https://keys.datadoghq.com/DATADOG_RPM_KEY_B01082D3.public
          https://keys.datadoghq.com/DATADOG_RPM_KEY_FD4BF915.public
   ```

**Note**: On i386/i686 architecture, replace "x86_64" with "i386".

1. Update your local YUM repo and install the Agent:

   ```shell
   sudo yum makecache
   sudo yum install datadog-agent
   ```

1. Copy the example config into place. Replace `MY_API_KEY` with your Datadog API key:

   ```shell
   sudo sh -c "sed 's/api_key:.*/api_key:MY_API_KEY /' /etc/dd-agent/datadog.conf.example > /etc/dd-agent/datadog.conf"
   ```

1. Restart the Agent:

   ```shell
   sudo /etc/init.d/datadog-agent restart
   ```

### Uninstall{% #uninstall %}

To uninstall the Agent, run the following command:

```shell
sudo yum remove datadog-agent
```

This command removes the Agent, but does not remove:

- The `datadog.yaml` configuration file
- User-created files in the `/etc/dd-agent` configuration folder
- User-created files in the `/opt/datadog-agent` folder
- The `dd-agent` user
- Datadog log files

If you also want to remove these elements, run this command after removing the Agent:

```shell
sudo userdel dd-agent \
&& sudo rm -rf /opt/datadog-agent/ \
&& sudo rm -rf /etc/dd-agent/ \
&& sudo rm -rf /var/log/datadog/
```

{% /tab %}

{% tab title="Suse" %}
### One-step install{% #one-step-install %}

The one-step command installs the YUM packages for the Datadog Agent and prompts you for your password. If the Agent is not already installed on your machine and you don't want it to start automatically after the installation, prepend `DD_INSTALL_ONLY=true` to the command before running it.

Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
DD_API_KEY=MY_API_KEY bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/install_agent.sh)"
```

### Multi-step install{% #multi-step-install %}

1. Set up the Datadog YUM repo by creating `/etc/yum.repos.d/datadog.repo` with the following contents:

   ```
   [datadog]
   name=Datadog, Inc.
   enabled=1
   baseurl=https://yum.datadoghq.com/suse/rpm/x86_64
   type=rpm-md
   gpgcheck=1
   repo_gpgcheck=0
   gpgkey=https://keys.datadoghq.com/DATADOG_RPM_KEY_B01082D3.public
   gpgkey=https://keys.datadoghq.com/DATADOG_RPM_KEY_FD4BF915.public
   ```

1. Update your local zypper repo and install the Agent:

   ```shell
   sudo zypper refresh
   sudo zypper install datadog-agent
   ```

1. Copy the example config into place. Replace `MY_API_KEY` with your Datadog API key:

   ```shell
   sudo sh -c "sed 's/api_key:.*/api_key: MY_API_KEY/' /etc/dd-agent/datadog.conf.example > /etc/dd-agent/datadog.conf"
   ```

1. Restart the Agent:

   ```shell
   sudo /etc/init.d/datadog-agent restart
   ```

### Uninstall{% #uninstall %}

To uninstall the Agent, run the following command:

```shell
sudo zypper remove datadog-agent
```

This command removes the Agent, but does not remove:

- The `datadog.yaml` configuration file
- User-created files in the `/etc/dd-agent` configuration folder
- User-created files in the `/opt/datadog-agent` folder
- The `dd-agent` user
- Datadog log files

If you also want to remove these elements, run this command after removing the Agent:

```shell
sudo userdel dd-agent \
&& sudo rm -rf /opt/datadog-agent/ \
&& sudo rm -rf /etc/dd-agent/ \
&& sudo rm -rf /var/log/datadog/
```

{% /tab %}

{% tab title="AIX" %}
### One-step install{% #one-step-install %}

The one-step command installs the latest BFF package for the Datadog Agent and prompts you for your password if necessary. If the Agent is not already installed on your machine and you don't want it to start automatically after the installation, prepend `DD_INSTALL_ONLY=true` to the command before running it.

Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
DD_API_KEY=MY_API_KEY bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/install_agent.sh)"
```

### Upgrade from a previous installation{% #upgrade-from-a-previous-installation %}

To install the Agent while keeping your existing configuration, run the following command:

```shell
DD_UPGRADE=true ksh -c "$(curl -L https://raw.githubusercontent.com/DataDog/datadog-unix-agent/master/scripts/install_script.sh)"
```

For a full list of the available installation script environment variables, see [Basic Agent Usage for AIX](https://docs.datadoghq.com/agent/basic_agent_usage/aix/#installation).

### Multi-step install{% #multi-step-install %}

1. Download the preferred BFF from the [datadog-unix-agent](https://github.com/DataDog/datadog-unix-agent/releases) repo releases:
1. Install the artifact as root with `installp`:
   ```shell
   installp -aXYgd datadog-unix-agent-latest.powerpc.aix..bff datadog-unix-agent
   ```
1. If you don't have an existing configuration file, copy the example config into place. Replace `MY_API_KEY` with your Datadog API key:
   ```shell
   sudo sh -c "sed 's/api_key:.*/api_key: MY_API_KEY/' /etc/datadog-agent/datadog.yaml.example > /etc/datadog-agent/datadog.yaml"
   ```
1. Ensure that the Datadog agent has the correct permissions:
   ```shell
   sudo sh -c "chown dd-agent:dd-agent /etc/datadog-agent/datadog.yaml && chmod 660 /etc/datadog-agent/datadog.yaml"
   ```
1. Stop the Agent service:
   ```shell
   sudo stopsrc -s datadog-agent
   ```
1. Verify the Agent service has stopped:
   ```
   sudo lssrc -s datadog-agent
   ```
1. Restart the Agent service:
   ```shell
   sudo startsrc -s datadog-agent
   ```

### Uninstall{% #uninstall %}

To uninstall the Agent, run the following command:

To remove an installed Agent, run the following `installp` command:

```shell
installp -e dd-aix-uninstall.log -uv datadog-unix-agent
```

Note: Agent uninstallation logs can be found in the `dd-aix-install.log` file. To disable this logging, remove the `-e` parameter in the uninstallation command.
{% /tab %}

## Cloud and containers{% #cloud-and-containers %}

{% tab title="Kubernetes" %}
## Install the Agent{% #install-the-agent %}

### Install with DaemonSets{% #install-with-daemonsets %}

If you're running Kubernetes >= 1.1.0, you can take advantage of [DaemonSets](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) to automatically deploy the Datadog Agent on all your nodes

1. Create a secret that contains your API key. This secret is used in the manifest to deploy the Datadog Agent. Replace `MY_API_KEY` with your Datadog API key:

   ```shell
   kubectl create secret generic datadog-secret --from-literal api-key =" MY_API_KEY"
   ```

1. Create the following manifest named `dd-agent.yaml`:

   ```yaml
   apiVersion: extensions/v1beta1
   kind: DaemonSet
   metadata:
   name: dd-agent
   spec:
   template:
      metadata:
         labels:
         app: dd-agent
         name: dd-agent
      spec:
         containers:
         - image: gcr.io/datadoghq/docker-dd-agent:latest
         imagePullPolicy: Always
         name: dd-agent
         ports:
            - containerPort: 8125
               name: dogstatsdport
               protocol: UDP
         env:
            - name: DD_API_KEY
               valueFrom:
               secretKeyRef:
                  name: datadog-secret
                  key: api-key
            - name: KUBERNETES
               value: "yes"
            - name: SD_BACKEND
               value: docker
            # Uncomment this variable if the agent has issues reaching kubelet
            # - name: KUBERNETES_KUBELET_HOST
            #   valueFrom:
            #     fieldRef:
            #       fieldPath: status.hostIP  # Kubernetes >= 1.7
            #       # or
            #       # fieldPath: spec.nodeName  # Kubernetes < 1.7
         resources:
            requests:
               memory: "256Mi"
               cpu: "200m"
            limits:
               memory: "256Mi"
               cpu: "200m"
         volumeMounts:
            - name: dockersocket
               mountPath: /var/run/docker.sock
            - name: procdir
               mountPath: /host/proc
               readOnly: true
            - name: cgroups
               mountPath: /host/sys/fs/cgroup
               readOnly: true
         livenessProbe:
            exec:
               command:
               - ./probe.sh
            initialDelaySeconds: 15
            periodSeconds: 5
         volumes:
         - hostPath:
               path: /var/run/docker.sock
            name: dockersocket
         - hostPath:
               path: /proc
            name: procdir
         - hostPath:
               path: /sys/fs/cgroup
            name: cgroups
   ```

1. Deploy the DaemonSet:

   ```shell
   kubectl create -f dd-agent.yaml
   ```

{% alert level="info" %}
This manifest enables autodiscovery's auto-configuration feature. To disable auto-configuration, remove the `SD_BACKEND` environment variable definition. To learn how to configure autodiscovery, see [Kubernetes Integrations Autodiscovery](https://docs.datadoghq.com/containers/kubernetes/integrations/?tab=kubernetesadv2).
{% /alert %}

### Run the Agent as a Docker container{% #run-the-agent-as-a-docker-container %}

If you are not running Kubernetes 1.1.0 or later, or you don't want to use DaemonSets, run the Agent as a Docker container on each node you want to monitor. Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
docker run -d --name dd-agent -h `hostname` -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e API_KEY=MY_API_KEY -e KUBERNETES=yes -e SD_BACKEND=docker gcr.io/datadoghq/docker-dd-agent:latest
```

## Send custom metrics{% #send-custom-metrics %}

If you plan on sending [custom metrics](https://docs.datadoghq.com/metrics/custom_metrics) using DogStatsD:

1. Bind the container's StatsD port to the node's IP address by adding a `hostPort` to the `ports` section of your manifest:

   ```yaml
   ports:
     - containerPort: 8125
       hostPort: 8125
       name: dogstatsdport
       protocol: UDP
   ```

1. Configure your client library to send UDP packets to the node's IP. If using bridge networking, the default gateway of your application container matches the node's IP. You can also use the downward API to expose the node's hostname as an environment variable.

## Customize your Agent configuration{% #customize-your-agent-configuration %}

To customize your Agent configuration, see the documentation in the Agent 5 [docker-dd-agent](https://github.com/DataDog/docker-dd-agent) repo. To tune autodiscovery configuration, see [Kubernetes Integrations Autodiscovery](https://docs.datadoghq.com/containers/kubernetes/integrations/?tab=kubernetesadv2). To disable autodiscovery, remove the `SD_BACKEND` environment variable from your manifest.

For information on collecting metrics, service checks, and events, see the [Kubernetes integration](https://docs.datadoghq.com/integrations/kubernetes/) documentation.
{% /tab %}

{% tab title="Docker" %}
### One-step install{% #one-step-install %}

The one-step install runs a Docker container which embeds the Datadog Agent to monitor your host. The Docker integration is enabled by default, as well as autodiscovery in auto config mode. To disable autodiscovery, remove the `SD_BACKEND` variable from the one-step install command.

#### Amazon Linux{% #amazon-linux %}

Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
docker run -d --name dd-agent -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /cgroup/:/host/sys/fs/cgroup:ro -e API_KEY=MY_API_KEY -e SD_BACKEND=docker gcr.io/datadoghq/docker-dd-agent:latest
```

#### Other operating systems{% #other-operating-systems %}

Run the following command, replacing `MY_API_KEY` with your Datadog API key:

```shell
docker run -d --name dd-agent -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e API_KEY=MY_API_KEY -e SD_BACKEND=docker gcr.io/datadoghq/docker-dd-agent:latest
```

#### Troubleshooting{% #troubleshooting %}

If the one-step install command does not work, it's possible that your system mounts the `cgroup` directory in an unexpected place or does not use CGroups for memory management. CGroups are required for the Docker check to succeed. To enable CGroups, see the documentation in the [docker-dd-agent](https://github.com/DataDog/docker-dd-agent?tab=readme-ov-file#cgroups) repo. If the check is failing because of an unexpected `cgroup` directory location:

1. Run `mount | grep "cgroup type tmpfs"` to retrieve the location of the `cgroup` directory.
1. Replace the first occurrence of `/sys/fs/cgroup` in the one-step install command with the location of the `cgroup` directory.

### Send custom metrics{% #send-custom-metrics %}

To send custom metrics using DogStatsD:

1. Add the `-p 8125:8125/udp` option to the install command. This binds the container's StatsD port to the host's IP address.
1. Configure your client library to send UDP packets to the host's IP address.

### Customize your Agent configuration{% #customize-your-agent-configuration %}

To customize your Agent configuration, see the documentation in the Agent 5 [docker-dd-agent](https://github.com/DataDog/docker-dd-agent) repo. To tune autodiscovery configuration, see [Docker Integrations Autodiscovery](https://docs.datadoghq.com/containers/docker/integrations/?tabs=docker). To disable autodiscovery, remove the `SD_BACKEND` environment variable from the one-step installation command.
{% /tab %}

{% tab title="CoreOS" %}
Running CoreOS Container Linux is supported with the Docker runtime. For installation instructions, see Docker.

To run CoreOS Tectonic on Kubernetes, see Kubernetes.
{% /tab %}

{% tab title="OpenShift" %}
For information on installing Datadog with OpenShift, see the [datadog-openshift](https://github.com/DataDog/datadog-openshift) repo.
{% /tab %}

{% tab title="Cloud Foundry" %}

{% alert level="info" %}
The Datadog Agent BOSH release only works on Ubuntu and Red Hat stemcells.
{% /alert %}

1. Upload the Datadog Agent release to your BOSH Director:

   ```shell
   # BOSH CLI v1
   bosh upload release https://cloudfoundry.datadoghq.com/datadog-agent/datadog-agent-boshrelease-latest.tgz
   
   # BOSH CLI v2
   bosh upload-release https://cloudfoundry.datadoghq.com/datadog-agent/datadog-agent-boshrelease-latest.tgz
   ```

1. Configure Datadog as an addon in your runtime config. Replace `MY_API_KEY` with your Datadog API key::

   ```yaml
   # runtime.yml
   ---
   releases:
   - name: datadog-agent
      version: $UPLOADED_VERSION # e.g. 1.0.5140
   
   addons:
   - name: datadog
   jobs:
   - name: dd-agent
      release: datadog-agent
   properties:
      dd:
         use_dogstatsd: yes
         dogstatsd_port: 18125 # Many Cloud Foundry deployments have their own StatsD listening on port 8125
         api_key: MY_API_KEY
         tags: ["my-cloud-foundry-deployment"] # optional. Add any tags you wish
         # Optionally, enable any Agent Checks here
         # integrations:
         #   directory:
         #     init_config: {}
         #     instances:
         #       directory: "."
   ```

1. Add the runtime to your runtime config:

   ```shell
   # BOSH cli v1
   bosh update runtime-config runtime.yml
   
   # BOSH cli v2
   bosh update-runtime-config runtime.yml
   ```

1. Redeploy any existing deployments:

   ```shell
   # BOSH cli v1
   bosh deployment myDeployment.yml
   bosh -n deploy
   
   # BOSH cli v2
   bosh -n -d myDeployment deploy myDeployment.yml
   ```

{% /tab %}

## Configuration management{% #configuration-management %}

{% tab title="Ansible" %}

{% alert level="info" %}
The Datadog Ansible collection supports most Debian, RHEL-based and SUSE-based Linux distributions, macOS, and Windows.Requires Ansible version 2.10 or higher.
{% /alert %}

### Prerequisites{% #prerequisites %}

#### Windows{% #windows %}

Before you can use the Datadog Ansible Collection to manage Windows hosts, you must install the `ansible.windows` collection:

```shell
ansible-galaxy collection install ansible.windows
```

#### openSUSE and SLES{% #opensuse-and-sles %}

Before you can use the Datadog Ansible Collection to manage openSUSE/SLES hosts, you must install the `community.general` collection:

```shell
ansible-galaxy collection install community.general
```

### Install Datadog{% #install-datadog %}

1. Install the Datadog Ansible collection from Ansible Galaxy on your Ansible server:

   ```shell
   ansible-galaxy collection install datadog.dd
   ```

   - The Datadog Ansible collection is also available through the [Red Hat Automation Hub](https://console.redhat.com/ansible/automation-hub/repo/published/datadog/dd/) where it is officially certified by Red Hat.
   - Installing the collection is recommended. If needed, you can also install Datadog using the [standalone role](https://docs.datadoghq.com/agent/guide/ansible_standalone_role/#ansible-role-versus-ansible-collection).

1. To deploy the Datadog Agent on hosts, add the Datadog role and your API key to your playbook. Replace `MY_API_KEY` with your Datadog API key:

   ```yaml
   - hosts: servers
   tasks:
      - name: Import the Datadog Agent role from the Datadog collection
         import_role:
         name: datadog.dd.agent
   vars:
      datadog_api_key: "MY_API_KEY"
      datadog_agent_major_version: 5
   ```

To ensure that the Agent can group your hosts together, only use node hostnames that the Datadog Agent is tracking. You can check what hostnames the Agent is tracking using the following command:

   ```shell
   service datadog-agent info
   ```

## Specific Agent checks{% #specific-agent-checks %}

To use a specific Agent check or integration on one of your nodes, you can use the `datadog_checks` variable. Here is an example for the process check:

```yaml
- hosts: servers
  tasks:
    - name: Import the Datadog Agent role from the Datadog collection
      import_role:
        name: datadog.dd.agent
  vars:
    datadog_api_key: "MY_API_KEY"
    datadog_agent_major_version: 5
    datadog_checks:
      process:
        init_config:
        instances:
          - name: ssh
            search_string: ['ssh', 'sshd']
          - name: syslog
            search_string: ['rsyslog']
            cpu_check_interval: 0.2
            exact_match: true
            ignore_denied_access: true
```

You can find more examples of the Agent role usage on the Github repo for the [standalone role](https://github.com/DataDog/ansible-datadog/#role-variables).

### Metrics and events{% #metrics-and-events %}

To get metrics and events on Datadog after Ansible runs, see the Ansible callback project's [Github page](https://github.com/DataDog/ansible-datadog-callback).
{% /tab %}

{% tab title="Puppet" %}

{% alert level="info" %}
The `datadog_agent` module only supports Linux nodes.Requires Puppet Agent version 2.7 or higher.
{% /alert %}

1. Install the `datadog_agent` module from the [Puppet Forge](https://forge.puppetlabs.com/modules/datadog/datadog_agent/readme) on your Puppet server:

   - For fresh installs, run the `module install command`:
     ```shell
     puppet module install datadog-datadog_agent
     ```
   - If the module is already installed, upgrade it:
     ```shell
     puppet module upgrade datadog-datadog_agent
     ```

1. To deploy the Datadog agent on nodes, add this parametrized class to your manifests. Replace `MY_API_KEY` with your Datadog API key:

   ```puppet
   node "db1.mydomain.com" {
      class { "datadog_agent":
         api_key => "MY_API_KEY"
      }
   }
   ```

To ensure that the Agent can group your hosts together, only use node hostnames that the Datadog Agent is tracking. You can check what hostnames the Agent is tracking using the following command:

   ```shell
   service datadog-agent info
   ```

1. Enable reporting to Datadog on your Puppet server:

   1. Add the following parameters to `/etc/puppet/puppet.conf`:
      ```
      [master]
      report = true
      reports = datadog_reports
      pluginsync = true
      
      [agent]
      report = true
      pluginsync = true
      ```
   1. In your manifest, add the `puppet_run_reports` option to your Puppet server. For example:
      ```puppet
      node "puppet" {
         class { "datadog_agent":
            api_key            => "MY_API_KEY",
            puppet_run_reports => true
            }
      }
      ```

1. Run Puppet on your Puppet server to install all necessary dependencies.

1. Restart your Puppet server to begin receiving Puppet data in Datadog.

## Specific Agent checks{% #specific-agent-checks %}

To use a specific Agent check or integration on one of your nodes, see the relevant [integration manifest](https://github.com/DataDog/puppet-datadog-agent/tree/main/manifests/integrations) for a code sample. Here is an example for the elasticsearch integration:

```puppet
node "elastic-node1.mydomain.com" {
    class { "datadog_agent":
        api_key => ""
    }
    include "datadog_agent::integrations::elasticsearch"
}
```

{% /tab %}

{% tab title="Chef" %}

{% alert level="info" %}
Requires Chef version 10.14.x or higher.
{% /alert %}

1. Add the Datadog cookbook:

   - If you are using [Berkshelf](https://docs.chef.io/workstation/berkshelf/), add the cookbook to your Berksfile:

     ```shell
     cookbook 'datadog'
     ```

   - If you're not using Berkshelf, install the cookbook in to your repository using Knife:

     ```shell
     knife cookbook site install datadog 
     ```

1. Set the Datadog-specific attributes in either a role, environment, or another recipe. Replace `MY_API_KEY` with your Datadog API key:

   ```
   node.default['datadog']['api_key'] = "MY_API_KEY"
   # Use an existing application key or create a new one for Chef
   node.default['datadog']['application_key'] = "Generate Application Key"
   ```

1. Upload the updated cookbook to your Chef server:

   ```shell
   berks upload
   # or
   knife cookbook upload datadog
   knife cookbook list | grep datadog && 
   echo -e "e[0;32mdatadog cookbook - OKe[0m" ||
   echo -e "e[0;31mmissing datadog cookbook - OKe[0m"
   ```

1. Add the cookbook to your node's `run_list` or `role`:

   ```
   "run_list": [
    "recipe[datadog::dd-agent]"
   ]
   ```

1. Wait for the next scheduled `chef-client` run.

{% /tab %}

{% tab title="SaltStack" %}

{% alert level="info" %}
The Datadog Saltstack formula only supports Debian-based and RedHat-based systems.The following instructions add the Datadog formula to the base Salt environment. To add it to another Salt environment, replace references to `base` with the name of your Salt environment.
{% /alert %}

### Install using `gitfs_remotes`{% #install-using-gitfs_remotes %}

1. Install the [Datadog formula](https://github.com/DataDog/datadog-formula) in the base environment of your Salt Master node, using the `gitfs_remotes` option in your Salt Master configuration file (by default `/etc/salt/master`):

   ```yaml
   fileserver_backend:
   - roots # Active by default, necessary to be able to use the local salt files we define in the next steps
   - gitfs # Adds gitfs as a fileserver backend to be able to use gitfs_remotes
   
   gitfs_remotes:
   - https://github.com/DataDog/datadog-formula.git:
     - saltenv:
       - base:
       - ref: 3.0 # Pin here the version of the formula you want to use
   ```

1. Restart your Salt Master service:

   ```shell
   systemctl restart salt-master
   ```

or

   ```shell
   service salt-master restart
   ```

### Install by cloning the Datadog formula{% #install-by-cloning-the-datadog-formula %}

1. Clone the [Datadog formula](https://github.com/DataDog/datadog-formula) on your Salt Master node:
   ```shell
   mkdir -p /srv/formulas && cd /srv/formulas git clone https://github.com/DataDog/datadog-formula.git
   ```
1. Add the cloned formula to the base environment in the `file_roots` of your Salt Master configuration file (by default `/etc/salt/master`):
   ```yaml
   file_roots:
     base:
       - /srv/salt/
       - /srv/formulas/datadog-formula/
   ```

## Deploy the Agent to your hosts{% #deploy-the-agent-to-your-hosts %}

1. Add the Datadog formula to your top file (by default `/srv/salt/top.sls`):

   ```yaml
   base:
     '*':
       - datadog
   ```

1. Add a `datadog.sls` pillar file to your pillar directory (by default `/srv/pillar/`) and add your API key. Replace `MY_API_KEY` with your Datadog API key:

   ```yaml
   datadog:
     config:
       api_key: MY_API_KEY
     install_settings:
       agent_version: <AGENT5_VERSION>
   ```

1. Add the `datadog.sls` pillar file to the top pillar file (by default `/srv/pillar/top.sls`):

   ```yaml
   base:
     '*':
       - datadog
   ```

1. To use a specific Agent check or integration on one of your hosts, you can use the checks variable. Here is an example for the directory integration:

   ```yaml
   datadog:
     config:
       api_key: MY_API_KEY
     install_settings:
       agent_version: <AGENT5_VERSION>
     checks:
       directory:
         config:
           instances:
             - directory: "/srv/pillar"
               name: "pillars"
   ```

Refer to the formula [Github repository](https://github.com/DataDog/datadog-formula) for logs configuration, check examples, and advanced use cases.
{% /tab %}

## Install from source{% #install-from-source %}

{% alert level="info" %}
The Datadog Agent requires python 2.7 and `sysstat` on Linux.
{% /alert %}

Use the one-step source install script. Replace `MY_API_KEY` with your Datadog API key:

```shell
DD_API_KEY=MY_API_KEY sh -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/setup_agent.sh)"
```

The script installs the Agent in its own self-contained sandbox located at `~/.datadog-agent`.

To make the installation permanent, set up your `init` daemon to run `$sandbox_dir/bin/agent` with `$sandbox_dir` set at the current working directory. The sandbox directory is portable and can run from any location on your file system. The sandbox directory is set to `~/.datadog-agent` by default.

## Further reading{% #further-reading %}

- [The Datadog Agent](https://docs.datadoghq.com/agent/)
