Go: cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
A package using cgo needs a C compiler, but none is installed or CGO is disabled.
cgo: C compiler "gcc" not foundexec: "gcc": executable file not found in $PATHcgo: exec gcc: executable file not foundBinary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub Meaning
Install gcc (or build-essential / Xcode command line tools), or build without cgo with CGO_ENABLED=0 when pure-Go alternatives exist (e.g. modernc.org/sqlite instead of mattn/go-sqlite3). Minimal Docker images (alpine, scratch, golang:alpine) lack gcc by default.
Common causes
- Alpine/minimal image without gcc
- Cross-compiling with cgo-dependent packages
- Xcode CLT missing on macOS
- Windows without MinGW
- CGO_ENABLED=0 but a package requires cgo
⚡ Quick fix
apk add build-base/apt-get install -y build-essential/xcode-select --install- Use a pure-Go library and
CGO_ENABLED=0 - Cross-compile with a proper toolchain
Detailed fix by platform
Docker
RUN apk add --no-cache build-basein the build stage, copy the binary into a slim stage
How to diagnose
- Package — Needs cgo?
- Image — gcc present?
- Alternative — Pure Go?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- assignment mismatch: 1 variable but f returns 2 values Go: assignment mismatch: 1 variable but os.Open returns 2 values
- cannot assign to struct field m[k].f in map Go: cannot assign to struct field users["bob"].Age in map
- COPY failed COPY failed: file not found in build context / "/app/x": not found
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026