Go on a Mac: module cache, build cache and go clean flags, measured

By the Zofle team · 15 November 2026 · 4 min read

Go module cache and build cache sizes after building lazygit

Go keeps two caches outside your projects: downloaded modules and compiled packages. Neither is small once you build real programs, and they behave differently when you clear them. We built one well-known Go program from scratch with empty caches, then cleared each cache in turn and timed the rebuild, so you can pick the one worth clearing.

Where the two caches are

bash
go version
go env GOMODCACHE GOCACHE
du -sh "$(go env GOMODCACHE)" "$(go env GOCACHE)"
CacheDefault on a MacHoldsClear with
Module cache~/go/pkg/modDownloaded dependency zips and their unpacked sourcego clean -modcache
Build cache~/Library/Caches/go-buildCompiled packages and test resultsgo clean -cache
Test resultsinside the build cacheCached passing testsgo clean -testcache
Fuzz inputsinside the build cacheInteresting fuzz inputsgo clean -fuzzcache

On the Mac we measured, GOCACHE was 110 MB from light use and the module cache did not exist yet (Go 1.27.4). That changes fast once you build something with dependencies.

The test: lazygit, empty caches, three clears

We pointed GOMODCACHE and GOCACHE at a scratch folder so the Mac's own caches stayed untouched, then ran go install github.com/jesseduffield/lazygit@latest (v0.66.3, about 27.7 MiB as a binary). Same Mac, 10 cores, same network:

bash
export GOMODCACHE=/tmp/go/mod GOCACHE=/tmp/go/cache GOBIN=/tmp/go/bin
time go install github.com/jesseduffield/lazygit@latest
StepModule cacheBuild cacheTime
1. First install (download and build)102 MiB (25 MiB of it zip files)291 MiB21.4 s
2. Install again, nothing changedsamesame0.43 s
3. go clean -cache, then install102 MiB8 KB, then 290 MiB again8.1 s
4. go clean -modcache, then install0, then 102 MiB again290 MiB (kept)12.0 s

What it tells you:

  • The build cache is the larger and cheaper one. 291 MiB bought 8 seconds of compile time here; we did not test a bigger project, but the cache grows with the code you compile, and so does the time it saves.
  • The module cache costs the network. Clearing it saved 102 MiB and cost 12 s because everything downloaded again; with a slow connection or offline, you cannot rebuild at all.
  • Both are rebuilt on demand, nothing in your own code is lost, and a cleared cache can only make the next build slower.
  • The warm run (0.43 s) shows why not to clear them on a schedule: it is what makes go build feel instant.

Things that surprise people

  • The module cache is read-only on purpose, so rm -rf ~/go/pkg/mod fails with permission errors. Use go clean -modcache (or build with -modcacherw if you want to delete it by hand).
  • Downloaded toolchains (golang.org/toolchain@...) also live in the module cache. Clearing it removes any extra Go version Go fetched for a project, and it is downloaded again on demand.
  • go clean -cache also drops cached test results, so the first go test after it re-runs everything.
  • Container builds have their own caches. If you build Go inside Docker, see the [Docker Desktop disk article](https://zofle.com/articles/docker-desktop-mac-docker-raw-system-df-build-cache-disk-measured.html).

A sensible routine

bash
# see sizes first
du -sh "$(go env GOMODCACHE)" "$(go env GOCACHE)"
# gentle: only the test results
go clean -testcache
# when the build cache is huge and you don't mind one slow build
go clean -cache
# when you are short of space and online
go clean -modcache

For other developer caches that grow quietly, see Gradle, node_modules and friends and SwiftPM and CocoaPods caches.

Zofle shows your Mac storage by category and lets you move big, old files to the Trash with Undo, so you can see what is worth the effort before you run any command.

Download Zofle for Mac

Sources and method

  • Go documentation: go clean (-cache, -modcache, -testcache, -fuzzcache), Go modules reference: module cache, build and test caching.
  • Timings and sizes from one Apple silicon Mac (10 cores) on 15 November 2026 with Go 1.27.4, du in KB converted to MiB; one run per step, so treat seconds as indicative. The dependency versions were whatever lazygit v0.66.3 required that day.

Zofle Pro news

People signing up now will get Zofle Pro, with more features, for free when we launch it.

One email when it's ready. No spam, ever.