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
- 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
- Unset a hand-exported GOROOT so Go uses its built-in default.
shell
unset GOROOT
go env GOROOTHow 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
Go "build cache is required, but could not be located" - Fix in CIFix Go "build cache is required, but could not be located" in CI - GOCACHE is unset/unwritable and off is not…
Go "gccgo not supported" - Fix in CIFix Go build failing because gccgo was used in CI - a feature or flag is gc-only. Build with the standard gc…
Go "fork/exec /tmp: permission denied" - Fix in CIFix Go tests failing with "fork/exec /tmp/...: permission denied" in CI - /tmp is mounted noexec or restricte…