Skip to content
Latchkey

OpenTofu "tofu: command not found" in CI

The shell could not find a tofu executable on PATH. OpenTofu is a separate binary from terraform; if you only installed Terraform (or nothing), the tofu command does not exist on the runner.

What this error means

A step running tofu init or tofu plan fails with "tofu: command not found" and exit code 127, often on a runner that has terraform but not tofu.

bash
/home/runner/work/_temp/script.sh: line 1: tofu: command not found
Error: Process completed with exit code 127.

Common causes

OpenTofu was never installed on the runner

The workflow assumes tofu is present, but the GitHub-hosted image ships terraform, not OpenTofu. Nothing put the tofu binary on PATH.

setup-opentofu ran in a different job

The install step ran in another job; PATH changes do not carry across jobs, so the step calling tofu starts without it.

How to fix it

Install OpenTofu with setup-opentofu

  1. Add the opentofu/setup-opentofu action before any tofu step.
  2. Pin tofu_version so the same OpenTofu release runs every time.
  3. Keep the install in the same job as the tofu commands.
.github/workflows/ci.yml
- uses: opentofu/setup-opentofu@v1
  with:
    tofu_version: 1.9.0
- run: tofu version

Do not assume terraform means tofu

If a script calls terraform, it will not run OpenTofu. Update scripts to call tofu, or set TOFU_CLI wrappers deliberately; the two binaries are not interchangeable by name.

How to prevent it

  • Install OpenTofu explicitly with setup-opentofu in every job that uses it.
  • Pin tofu_version so CI does not silently drift.
  • Run tofu version as a first step to confirm the binary resolved.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →