How to Fix tree: command not found in Minimal Linux

Working in a command-line terminal on a Linux cloud server, bare-metal deployment, or Docker container and typing tree to visually inspect nested directory hierarchies only to receive the shell alert bash: tree: command not found (or sh: tree: not found) interrupts filesystem navigation. The tree utility is a recursive directory listing program that outputs a depth-indented visual graph of files, subdirectories, and symlinks directly in the terminal. Because standard minimal server images and cloud-init container base layers exclude optional command-line utilities to minimize container image sizes, tree is not bundled by default. Installing the package via official repository mirrors or utilizing built-in find fallback commands enables instantaneous directory visualization.

Install tree on Ubuntu, Debian, and Linux Mint

Debian-based distributions maintain official pre-compiled tree binaries within their main repository mirrors.

  1. Log into your server terminal as a privileged user or prepend commands with sudo.
  2. Update your local package repository index:
    sudo apt update
  3. Install the tree utility package:
    sudo apt install -y tree
  4. Verify successful binary deployment and check the version:
    tree --version
  5. Execute a test run limiting directory depth to two levels:
    tree -L 2

Install tree on RHEL, Rocky Linux, CentOS, and Alpine

Enterprise Linux platforms and lightweight container environments deploy the utility using native package managers.

  1. On RHEL 8/9, Rocky Linux, or AlmaLinux, install tree using DNF:
    sudo dnf install -y tree
  2. On older CentOS 7 distributions, install using Yum:
    sudo yum install -y tree
  3. On lightweight Alpine Linux containers, deploy via apk:
    apk update && apk add tree
  4. On Arch Linux, execute:
    sudo pacman -S --noconfirm tree

Use Native find and sed Commands as an Instant Alternative

If you are operating in an air-gapped system, unprivileged container, or environment without package installation privileges, built-in shell tools replicate tree output.

  1. Execute the following one-line shell pipeline to generate an indented visual directory structure:
    find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
  2. Alternatively, use native ls with recursive grouping flags:
    ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^/]*//--/g' -e 's/^/ /' -e 's/-/|/'
  3. These native POSIX pipelines run immediately across all Linux distributions without requiring root permissions or external network package downloads.

Get the best tech tips delivered straight to your inbox.

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