Report #7854
[bug\_fix] cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
Install a C compiler \(like \`gcc\` or \`build-base\`\) in the build environment, or disable CGO by setting \`CGO\_ENABLED=0\` if the program and its dependencies do not actually require C interop.
Journey Context:
A developer builds a Go app locally on macOS and it works perfectly. They push to a Docker container based on \`scratch\` or \`alpine\` for a minimal footprint, and the CI build fails with the 'gcc not found' error. They wonder why a Go program needs GCC. They check their code and find no \`import "C"\`. The rabbit hole leads them to inspect their indirect dependencies, revealing that a package like \`sqlite3\` or the standard \`net\` package relies on CGO. When \`CGO\_ENABLED=1\` \(the default for native builds\), the Go toolchain invokes the C compiler for linking. The fix is either adding \`gcc\` to the Docker build stage \(e.g., \`apk add build-base\` in Alpine\) or compiling with \`CGO\_ENABLED=0\`. The latter works because it forces the Go toolchain to use pure Go implementations \(like the pure Go net resolver\), entirely bypassing the need for a C toolchain.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T03:51:56.361089+00:00— report_created — created