SiftMac
Is it safe to delete? · Package caches · Updated 21 November 2026

Is it safe to delete ~/go/pkg/mod and Go’s build cache?

By Mohit Nippanikar, who makes SiftMac

The short answer
On this page
  1. Two caches
  2. Where they are
  3. How big they get
  4. How to clear them
  5. What happens afterwards
  6. Questions

1. Two caches

Go creates module files and folders read-only so tests and editors can’t change a dependency after it was checked against go.sum. That protection is also why deleting the folder by hand fails with permission errors.

2. Where they are

~/go/pkg/mod
~/Library/Caches/go-build

The module cache is pkg/mod inside GOPATH, which defaults to ~/go. The build cache is a go-build folder in your Mac’s user cache folder. Print both:

go env GOMODCACHE GOCACHE

3. How big they get

du -sh "$(go env GOMODCACHE)" "$(go env GOCACHE)"

Since nothing trims it, the module cache is the one that keeps growing: every version of every module, across all your projects and every upgrade.

4. How to clear them

go clean -modcache
go clean -cache

If you’d rather rm -rf worked in future, go env -w GOFLAGS=-modcacherw makes new module folders writable. Go’s docs ask for caution with it, since writable modules can be changed by accident; go mod verify detects such changes.

5. What happens afterwards

Questions

Why does rm -rf ~/go/pkg/mod say Permission denied?

Go creates module files and folders read-only to protect them from accidental edits, and rm can’t remove files from a folder it can’t write to. go clean -modcache handles that for you.

Is it safe to delete ~/go entirely?

Usually not. Besides the cache, ~/go/bin holds tools you installed with go install, and older projects may keep code in ~/go/src. Clear pkg/mod with go clean -modcache instead.

Does Go clean these caches by itself?

The build cache, yes: Go periodically deletes entries that haven’t been used recently. The module cache, no: it has no size limit and stays until you clean it.

Can several Go projects share the module cache safely?

Yes. Every project on the Mac uses the same module cache, and Go’s reference says several go commands can safely use it at the same time.

How SiftMac handles it. Its App caches category clears Go’s build cache in ~/Library/Caches/go-build as a download cache with a Rebuilds verdict. It leaves the module cache in ~/go/pkg/mod to go clean -modcache, which handles its read-only files; the space map shows how big it is.

Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works