Is It Safe to Delete the Go Module Cache (~/go/pkg/mod) on a Mac?

Yes, with the right methodDiskmack safety tier: Safe to clean
~/go/pkg/mod

Yes, you can clear the Go module cache safely, but use go clean -modcache rather than deleting the folder by hand. Go writes the files in ~/go/pkg/mod as read-only, so plain deletion often stops with permission errors. Everything in there is re-downloaded on your next go build, so the worst case is a slower first compile and some extra bandwidth. Your source code is not touched.

What it is

~/go/pkg/mod is the Go module cache. Every time you run go build, go test, or go mod download, the Go toolchain fetches the source code of your dependencies (usually from proxy.golang.org), verifies each one against a checksum database, and unpacks it here. The cache is shared across every Go project on your Mac, which is why it lives in your home directory instead of inside any single repo.

It grows because Go keeps every version of every module you have ever pulled. Switch a project from v1.9.0 of a library to v1.10.0 and both versions stay on disk. Clone a few open source Go projects to poke at them and their whole dependency trees land here too. On a machine that sees regular Go work, the cache commonly reaches several gigabytes, and heavy multi-project setups can go well past 10 GB. Nothing inside it is unique to you: it is all downloadable source code, plus a cache/download subfolder holding the original zip archives and checksum metadata.

Is it safe to delete?

This folder is safe to clear. It holds cached copies of public (or your company's private) module source, not your code and not your Go installation. Delete it and the next go build re-downloads exactly the modules your current projects need, at their pinned versions from go.mod and go.sum. You lose nothing permanently; you pay with download time on the first build afterward, which on a normal connection is minutes, not hours.

The one quirk is the deletion method. Go deliberately strips write permission from the cached files so that nothing edits them by accident (a classic case is jump-to-definition dropping you into a dependency's source, where one stray keystroke would poison every project sharing the cache). The side effect is that a casual delete can fail halfway with permission errors. The official command, go clean -modcache, resets the permissions and removes everything cleanly. Diskmack detects this folder automatically and clears it using that same official command.

How to check its size

In Finder: In Finder, choose Go > Go to Folder from the menu bar (or press Shift-Command-G), paste ~/go/pkg and press Return. Click the mod folder once to select it, then press Command-I to open Get Info and read the size. Calculating it can take a minute for a big cache.

In Terminal:

du -sh ~/go/pkg/mod

The ~ expands to your home folder, for example /Users/yourname/go/pkg/mod. If you have set a custom GOMODCACHE or GOPATH, run go env GOMODCACHE first to see the real location.

How to clean it

  1. Quit anything that might be compiling Go code right now, such as VS Code or GoLand with a build running.
  2. Open Terminal (Applications > Utilities > Terminal).
  3. Type go clean -modcache and press Return. It finishes silently; no output means it worked.
  4. Check the result with du -sh ~/go/pkg/mod. If it reports "No such file or directory", that is success: the command removes the whole folder, not just its contents.
  5. If you prefer Finder: Go > Go to Folder, enter ~/go/pkg, drag the mod folder to the Trash, and confirm if Finder warns about locked or read-only items. Then empty the Trash.

The official way: this tool ships its own cleanup command, which handles locks and indexes correctly.

go clean -modcache

The command wipes the whole cache; there is no built-in way to clear just one module or prune old versions. If your GOMODCACHE points somewhere custom, the command cleans that location, not ~/go/pkg/mod.

Will it come back?

Yes, and that is by design. The next time you build or test any Go project, the toolchain re-downloads its dependencies into ~/go/pkg/mod, so the folder starts refilling within seconds of your next build. The useful part: it only refills with modules your current projects actually import. All the old versions and dependencies of long-deleted experiments stay gone, so a freshly rebuilt cache is usually a fraction of the size of the one you cleared. If you build Go code daily, expect it to creep back up over months, and clear it again whenever it gets fat.

Common questions

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

Go marks the cached files read-only to protect them from accidental modification, so plain delete commands stop with permission denied errors partway through. go clean -modcache handles the permissions for you and is the supported method. Finder can usually trash the folder too, but it may warn about locked items.

Will clearing the module cache break my Go projects?

No. Each project's go.mod and go.sum files record exactly which modules and versions it needs. The next go build fetches them again and verifies the checksums, so you end up with byte-identical dependencies. The only cost is the re-download.

Is this the same as the Go build cache?

No. The build cache holds compiled artifacts and lives at ~/Library/Caches/go-build on macOS. It is also safe to clear, with go clean -cache, at the cost of slower rebuilds. The module cache at ~/go/pkg/mod only holds downloaded source.

I don't write Go. Why do I have this folder?

Some tool you installed was built or fetched with the Go toolchain, or you once ran go install for a utility. If Go itself is gone from your machine, the leftover cache does nothing and you can trash the entire ~/go folder. Look inside it first: ~/go/bin can hold command line tools you still use, and ~/go/src can hold code someone checked out on purpose. If both are empty or missing, trash away.

Related folders