The error message “bash: lsof: command not found” surfaces in Linux terminal sessions when system administrators attempt to list open files, identify listening network sockets, or track down processes locking mount points on minimal server distributions, cloud images, or Docker containers. The lsof (List Open Files) utility is frequently omitted from minimal system templates to reduce package footprint and streamline container images.
Install lsof on Debian and Ubuntu Systems
On Debian, Ubuntu, Linux Mint, and derivative operating systems, lsof is hosted within the default upstream repositories:
- Synchronise the local APT package repository index:
sudo apt update - Install the lsof package binary:
sudo apt install -y lsof - Confirm the installation by verifying the binary version:
which lsof lsof -v
Install lsof on RHEL, CentOS, Rocky Linux, and Fedora
Enterprise Linux distributions manage the diagnostic tool through the DNF and YUM package managers:
- On Fedora, RHEL 8/9, Rocky Linux, and AlmaLinux:
sudo dnf install -y lsof - On older CentOS 7 installations:
sudo yum install -y lsof - Query the package registration details to verify proper binary placement:
rpm -q lsof
Install lsof in Alpine Linux Docker Containers
Alpine Linux container images use stripped-down BusyBox utilities that lack full lsof capabilities by default:
- Update the Alpine package repository index:
apk update - Install the standalone lsof package:
apk add lsof - If building customized container images, include the tool in your Dockerfile definition:
RUN apk add --no-cache lsof
Install lsof on Arch Linux and Manjaro
Arch Linux packages lsof in the core repository:
- Synchronise repository databases and install the package via Pacman:
sudo pacman -Sy lsof - Verify that your user has adequate permissions to inspect process file descriptors:
sudo lsof -i :80
Installing the lsof package restores full file descriptor inspection, open socket diagnostics, and port monitoring across minimal Linux environments.