~/go/pkg/mod is Go's module cache, where the go command keeps downloaded dependencies for all your projects. It is safe to clear. Run go clean -modcache, because the files are read-only and rm may complain. Go downloads the modules again the next time a build needs them.
- Path
~/go/pkg/mod- What it is
- Downloaded Go modules, stored read-only
- Typical size
- Hundreds of megabytes to several gigabytes across many projects
- Made by
- The go command
- Safe to delete?
- Safe to clear
- Comes back?
- Yes, go build or go mod download fetches modules again
What is in this folder?
By default the module cache is at $GOPATH/pkg/mod, and $GOPATH defaults to ~/go. The Go Modules Reference says Go creates read-only files there to prevent accidental changes. Each version of each module has its own folder, so older versions pile up. Run go env GOMODCACHE to see the path.
Your own Go source code lives in your project folders, not here.
Is it safe to delete?
Yes. The cache is rebuilt from the module proxy, and go.sum in each project verifies the downloads. The cost is download time, and you need network access for the next build.
The sibling folder ~/go/bin holds programs you installed with go install. Leave it alone unless you want to remove them.
How do I clear it by hand?
- Stop any running
go buildor editor language server (gopls). - Run the Go command, which handles the read-only files.
- Build a project to download what it needs.
go env GOMODCACHE
go clean -modcachePrefergo clean -modcachetorm -rf, since the cache files are read-only. Rungo clean -cacheseparately for the build cache.
How do I stop it growing?
Run go clean -modcache occasionally. Go does not trim the module cache itself.
How Clean House handles it
Clean House recognizes ~/go/pkg/mod as a Go modules cache made by Go and marks it as downloading again. The Why card spells that out before you clear it, and files go to the Trash first, with Recently Cleared as an undo.