Go on a Mac: module cache, build cache and go clean flags, measured
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
| Cache | Default on a Mac | Holds | Clear with |
|---|---|---|---|
| Module cache | ~/go/pkg/mod | Downloaded dependency zips and their unpacked source | go clean -modcache |
| Build cache | ~/Library/Caches/go-build | Compiled packages and test results | go clean -cache |
| Test results | inside the build cache | Cached passing tests | go clean -testcache |
| Fuzz inputs | inside the build cache | Interesting fuzz inputs | go 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:
| Step | Module cache | Build cache | Time |
|---|---|---|---|
| 1. First install (download and build) | 102 MiB (25 MiB of it zip files) | 291 MiB | 21.4 s |
| 2. Install again, nothing changed | same | same | 0.43 s |
3. go clean -cache, then install | 102 MiB | 8 KB, then 290 MiB again | 8.1 s |
4. go clean -modcache, then install | 0, then 102 MiB again | 290 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 buildfeel instant.
Things that surprise people
- The module cache is read-only on purpose, so
rm -rf ~/go/pkg/modfails with permission errors. Usego clean -modcache(or build with-modcacherwif 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 -cachealso drops cached test results, so the firstgo testafter 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
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 MacSources 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.