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

Is it safe to delete? · Package caches · Updated 21 November 2026. By Mohit Nippanikar, who makes SiftMac.

## The short answer

- **Yes**, with Go’s own commands. The module cache holds downloaded dependencies and the build cache holds compiled packages, and both come back. Use `go clean`, because module files are read-only and `rm -rf` fails on them.
- **What it costs you:** the next build downloads modules again and compiles from scratch.
- **Does it come back?** Yes. The build cache trims itself; the module cache only grows until you clean it.
- SiftMac’s verdict: Rebuilds

## 1. Two caches

- **The module cache** (`GOMODCACHE`) holds the source of every module version your projects downloaded, plus the original zip and `go.mod` files under `cache/download`. Go’s reference says it has no maximum size and the `go` command doesn’t remove its contents automatically.
- **The build cache** (`GOCACHE`) holds compiled packages and test results, so unchanged code isn’t compiled twice. The `go` command periodically deletes data in it that hasn’t been used recently.

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
```

- `go clean -modcache` removes the entire module cache, unpacked source included. Go’s reference calls it usually the best way, because it deals with the read-only permissions for you.
- `go clean -cache` removes the entire build cache.
- `go clean -testcache` only expires cached test results, if stale passes are the problem.
- Leave `go clean -fuzzcache` alone unless you mean it: it deletes inputs the fuzzer found that expand coverage, which makes fuzzing less effective.

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

- The next `go build`, `go test` or editor load downloads the modules in `go.mod` again through your module proxy and checks them against `go.sum`.
- The first build compiles everything; later builds are quick again as the build cache refills.
- Projects that vendor their dependencies in a `vendor` folder build without downloading.
- Programs you installed with `go install` keep working. They live in `~/go/bin`, which `go clean -modcache` doesn’t touch.

## 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: https://siftmac.com/SiftMac.dmg (scanning is free, and so is the first 2 GB of cleaning).

## Sources

- [Go Modules Reference: the module cache and go clean -modcache](https://go.dev/ref/mod#module-cache)
- [Go command documentation: build and test caching, go clean](https://pkg.go.dev/cmd/go)

## Related

- [Is it safe to delete ~/.cargo/registry and ~/.cargo/git?](https://siftmac.com/safe-to-delete/cargo-registry)
- [Is it safe to delete ~/Library/Caches on a Mac?](https://siftmac.com/safe-to-delete/library-caches)
- [Xcode DerivedData, node_modules and Docker: what’s safe to delete on a developer’s Mac](https://siftmac.com/guides/developer-files-on-mac)
- [What fills a developer’s Mac, and what’s safe to delete](https://siftmac.com/for/developers)

Canonical: https://siftmac.com/safe-to-delete/go-module-cache
