← All guides

Clear Go's module and build caches

CacheCleaner guides · Updated July 18, 2026

Go has two hoards: the module cache (~/go/pkg/mod) with every version of every dependency you ever fetched, and the build cache (~/Library/Caches/go-build). Together 5-30 GB is normal. Both are fully regenerable.

See the sizes

du -sh $(go env GOMODCACHE) $(go env GOCACHE)

Clear them

go clean -modcache     # module downloads – re-fetched on next build
go clean -cache        # build cache – next builds recompile everything
go clean -testcache    # cached test results only (tiny, but handy)

The module cache is stored read-only, so if you ever tried rm -rf and hit permission errors – that's why. Use go clean -modcache, it handles the permissions.

Old toolchains

ls ~/go/pkg/mod/golang.org/toolchain@*   # auto-downloaded Go versions, ~250 MB each

Since Go 1.21 the toolchain auto-downloads newer versions per project – they accumulate in the module cache and go away with -modcache too.

CacheCleaner picks up both Go caches in its dev-tools scan, next to cargo, npm, gradle and the rest – sizes visible before you decide.

Get CacheCleaner for Mac