Skip to content
Latchkey

Go "cannot find GOROOT directory" in CI - Fix the build

GOROOT is where the Go toolchain lives. If it points at a directory that does not exist, the go command cannot find its own standard library and refuses to run.

What this error means

A go command fails immediately with go: cannot find GOROOT directory: /usr/local/go. It usually means a hand-set GOROOT env var is stale, or a cached path no longer matches the installed toolchain.

go
go: cannot find GOROOT directory: /usr/local/go

Common causes

Stale GOROOT environment variable

A pinned GOROOT points at an install path that the current runner image does not have.

Cached path from a different setup

A cache or earlier step set GOROOT to a location the actual Go install no longer uses.

How to fix it

Stop hard-coding GOROOT

  1. Remove any manual GOROOT export and let setup-go configure it.
.github/workflows/ci.yml
- uses: actions/setup-go@v5
  with:
    go-version: '1.22'
# do not set GOROOT manually

Point GOROOT at the real install

  1. If you must set it, derive it from the installed go binary.
Terminal
export GOROOT="$(go env GOROOT)"

How to prevent it

  • Let setup-go own GOROOT instead of hard-coding it.
  • Avoid caching absolute toolchain paths across images.
  • Use go env GOROOT if a value is genuinely needed.

Frequently asked questions

What causes ""cannot find GOROOT""?
A pinned GOROOT points at an install path that the current runner image does not have.
How do I fix "cannot find GOROOT"?
Stop hard-coding GOROOT

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card