Go "package fmt is not in std" (broken GOROOT) - Fix in CI
By Daniel Zoghalchali·Latchkey
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@v5with: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 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.
Frequently asked questions
What causes ""package fmt is not in std""?
An exported GOROOT points at a directory without a real standard library tree.