How to Fix bash: ping: command not found in Linux

Attempting to troubleshoot network latency or server reachability in a Linux terminal only to be stopped by bash: ping: command not found or sh: ping: not found is common in minimal cloud images, Docker containers, and lightweight server installations. To minimise attack surfaces and container image sizes, modern distributions (including Ubuntu, Debian, Alpine, and Red Hat) deliberately omit the legacy iputils-ping suite from base images. Installing the official network diagnostics package restores complete ICMP ping functionality immediately.

Install iputils-ping on Ubuntu and Debian Distributions

On Debian, Ubuntu, and related derivatives, the ping binary is packaged inside the iputils-ping package rather than a standalone package named ping.

  1. Update your local package repository index:
    sudo apt update
  2. Install the iputils-ping package:
    sudo apt install -y iputils-ping
  3. Verify installation by checking the ping version or testing local loopback:
    ping -c 3 127.0.0.1
  4. The utility will cleanly execute and display standard ICMP packet transmission metrics.

Install iputils on RHEL, CentOS, Fedora, and Rocky Linux

On enterprise RPM-based distributions, the networking tools are bundled inside the standard iputils meta-package.

  1. Update your package manager repository data:
    sudo dnf check-update || sudo yum check-update
  2. Install the core network utilities:
    sudo dnf install -y iputils
  3. For older CentOS/RHEL 7 systems, execute:
    sudo yum install -y iputils
  4. Test execution:
    ping -c 3 8.8.8.8

Install iputils in Alpine Linux Docker Containers

Alpine Linux is popular for containerisation due to its tiny 5 MB base image footprint, using BusyBox by default. If your minimal Alpine environment lacks ICMP utilities, add them via apk.

  1. Inside your Alpine shell or Dockerfile, execute:
    apk update && apk add iputils
  2. Alternatively, if you require only the lightweight BusyBox implementation without full iputils features:
    apk add iputils-ping
  3. If building an automated Dockerfile, append the package to your build layer:
    RUN apk update && apk add --no-cache iputils

Troubleshoot Non-Root ICMP Socket Permissions (Cap_net_raw)

In certain hardened container environments (such as Kubernetes or unprivileged Docker runs), non-root users may encounter ping: socket: Operation not permitted even after installing the binary.

  • Linux requires raw network socket capabilities (CAP_NET_RAW) to craft ICMP packets.
  • To grant the necessary Linux capability to the ping executable without granting full root privileges, execute:
    sudo setcap cap_net_raw+ep $(which ping)
  • Alternatively, configure your host container runtime security profile by passing --cap-add=NET_RAW when launching Docker containers.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.