What is ~/go/pkg/mod on Mac, and is it safe to delete?
You can delete the Go module cache, and Go downloads modules again when you next build. Use go clean -modcache to do it, because the files are read-only and Finder or rm will complain.
Where it is
~/go/pkg/modWhat it is
When a Go project needs a dependency, the go command downloads that module version into the module cache, by default ~/go/pkg/mod. Every project on your Mac shares this one cache.
It grows because each version of each module is stored separately and nothing removes old ones. A few large dependency trees can add up quickly.
Go marks the cached files read-only on purpose, so that builds cannot modify them by accident. That is why deleting the folder by hand produces permission errors.
How big it gets
Usually a few GB for regular Go development.
How to clear it by hand
- Open Terminal.
- Run the command below. It deletes the entire module download cache, including unpacked source for every dependency version.
- If you set GOMODCACHE or GOPATH to a different location, the command still clears the right folder. You can check the location with go env GOMODCACHE.
go clean -modcacheWhat happens afterwards
The next go build or go test in each project downloads its dependencies again, so it is slower and needs a network connection. Your own code and installed Go binaries are not removed.
How Diskzy handles it
Diskzy lists the Go module cache in the Clean up tab but leaves it unticked, because your next build would have to download everything again.
Related guides
See where your Mac's space went
Diskzy maps your disk, explains System Data and clears what's safe. Free for 72 hours, then $9 once for 2 Macs.
Try Diskzy for free