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.
/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
- Add the
opentofu/setup-opentofuaction before anytofustep. - Pin
tofu_versionso the same OpenTofu release runs every time. - Keep the install in the same job as the
tofucommands.
- uses: opentofu/setup-opentofu@v1
with:
tofu_version: 1.9.0
- run: tofu versionDo 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_versionso CI does not silently drift. - Run
tofu versionas a first step to confirm the binary resolved.