Guide

How to clear Go cache on Mac, with go clean.

Go keeps two caches in two different places: one for build results, one for downloaded modules. Each has its own flag, and the module cache is read-only on purpose.

The short version

Run go clean -cache to empty the build cache, which on a Mac is ~/Library/Caches/go-build. Run go clean -modcache to remove every downloaded module from ~/go/pkg/mod. Both rebuild on the next go build, which downloads modules again. Use go clean for the module cache: its files are read-only, so the Trash and rm both fail.

Where Go keeps its cache on a Mac

go env GOCACHE GOMODCACHE
WhatDefault locationOn one Mac
Build cache (GOCACHE)~/Library/Caches/go-build258 MB
Module cache (GOMODCACHE)~/go/pkg/mod24 MB

Sizes are from one developer Mac with Go 1.26 in October 2026. The build cache follows the Mac convention and lives in ~/Library/Caches. The module cache lives under GOPATH, which is ~/go unless you've changed it. Set GOCACHE or GOMODCACHE with go env -w to move them.

go clean flags for every cache

go clean -cache        # the build cache
go clean -testcache    # only cached test results
go clean -modcache     # every downloaded module
go clean -fuzzcache    # inputs saved by go test -fuzz
  • -cache removes compiled packages and cached test results. The next build compiles everything from source, which takes longer for big projects. Safe.
  • -testcache keeps compiled code and only forgets test results, so go test runs every test again. Use it when a cached “ok” is hiding a flaky test; it frees almost nothing.
  • -modcache removes the source of every module you've downloaded. The next build downloads them again, from the Go module proxy by default. Safe if you're online; vendored projects don't need it at all.
  • -fuzzcache removes the inputs that fuzzing found interesting. Only clear it if you don't need to replay them.

Why go clean -modcache, not the Trash

Go makes every file in the module cache read-only, so nothing edits a dependency by accident. That's why moving ~/go/pkg/mod to the Trash fails partway, and rm -rf prints “Permission denied” over and over. go clean -modcache fixes the permissions and removes it cleanly. If you'd rather have a cache you can delete normally, build with -modcacherw, or add it to GOFLAGS.

The build cache has no such problem. You can move ~/Library/Caches/go-build to the Trash, though go clean -cache does the same thing.

How big Go caches get

Go trims its own build cache: entries unused for about five days are removed as you build. So the build cache stays at a few hundred megabytes to a few gigabytes; on the Mac above, it was 258 MB. The module cache is never trimmed. Each version of each module stays until you clear it, so a Mac that has built many projects over a few years can hold several gigabytes. The go toolchains Go downloads for toolchain lines in go.mod live in the module cache too, at a few hundred megabytes each.

Also writing Rust? See cargo clean. Or Homebrew, and every tool's cache.

Disk Forecast finds this for you

Go's build cache lives in ~/Library/Caches, so Disk Forecast lists it as the go-build entry under Cleanup › Safe to clear › App caches, and moves it to the Trash. The module cache in ~/go/pkg/mod isn't listed, since its read-only files are a job for go clean -modcache. Disk Forecast also shows where your space goes and forecasts when your disk will be full. It's free.

Questions

How do I clear the Go cache?

Run go clean -cache to empty the build cache, and go clean -modcache to remove downloaded modules. Both are safe; the next build compiles from source and downloads modules again.

What does go clean -modcache do?

It removes the entire module download cache, ~/go/pkg/mod by default, including the unpacked source of every module version. Go downloads what a project needs again on the next build.

Where is the Go build cache on a Mac?

In ~/Library/Caches/go-build. Run go env GOCACHE to confirm. The module cache is separate, in ~/go/pkg/mod; go env GOMODCACHE shows it.

Why can't I delete ~/go/pkg/mod?

Go makes module cache files read-only so dependencies can't be edited by accident. Use go clean -modcache, which handles the permissions, instead of the Trash or rm.

Know before it's full.

Free. No account, no subscription.

macOS 14 or later · Apple Silicon and Intel · brew install --cask coreyhaines31/tap/diskforecast