Bottom Line: It is 100% safe to clear the Go build and module cache. Running go clean -cache will not delete your Go source code (.go files) or project dependencies.
What is the Go Build Cache Folder?
Located at ~/.cache/go-build on Linux/macOS or %LocalAppData%\go-build on Windows (plus $GOPATH/pkg/mod), this directory is created by the Go (Golang) compiler.
When you compile or test Go programs using go build or go test, Go caches compiled package object files so future builds compile instantly. Additionally, go get caches downloaded dependency modules in $GOPATH/pkg/mod.
Over months of building Go applications, these caches accumulate old package versions, taking up 5 GB to 20 GB+.
Can You Delete the Go Cache?
✅ Yes, it is completely safe to delete.
- No source code lost: Your
.gocode files,go.mod, andgo.sumfiles are untouched. - Auto-download on demand: Go will re-download modules and re-compile packages on your next
go build.
How to Safely Clean Up Go Cache
Method 1: Using Built-in go clean Commands (Recommended)
To purge all compiled Go build artifacts:
go clean -cache
To purge downloaded module dependencies in $GOPATH/pkg/mod:
go clean -modcache
To purge both build cache and module cache in one command:
go clean -cache -modcache -testcache
Related Guides
- Learn about deleting [Rust Cargo target))))))))))))))))))))))) folder].
- How to clean up pip cache.
- Check if you can clean node_modules.
Discussion
Loading authentication...