Skip to content
Latchkey

Go "package fmt is not in std" (broken GOROOT) - Fix in CI

When even fmt resolves as "not in std", GOROOT points somewhere without a valid standard library. The install is broken or GOROOT was set to a stale or wrong path.

What this error means

A build fails with package fmt is not in std (GOROOT/src/fmt) for a stdlib import. GOROOT is misconfigured or the Go install is incomplete.

go
main.go:3:8: package fmt is not in std (/opt/wrong-go/src/fmt)

Common causes

GOROOT set to a wrong path

An exported GOROOT points at a directory without a real standard library tree.

Broken or partial Go install

The toolchain was installed incompletely, so even the standard library is missing.

How to fix it

Reinstall Go cleanly

  1. Install Go via setup-go and let it manage GOROOT.
.github/workflows/ci.yml
- uses: actions/setup-go@v5
  with:
    go-version: '1.22'

Clear a stale GOROOT override

  1. Unset a hand-exported GOROOT so Go uses its built-in default.
shell
unset GOROOT
go env GOROOT

How to prevent it

  • Let setup-go manage GOROOT instead of exporting it by hand.
  • Avoid stale GOROOT exports left in profiles or caches.
  • Verify go env GOROOT points at a real install.

Related guides

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