Is there a way to purge all the old packages from ~/go.apps/pkg/?

I don’t do any development in Go lang. The only “Go dev” stuff I do is clone the Hugo repo and build it locally to try out new features and bug fixes.

I have seen that over time, a lot of garbage gets collected in the ~/go.apps/pkg/ directory e.g. multiple versions of the same package.

I tried searching online but the name of the language “go” makes it very difficult to search for what I need.

For example, I have these pkg versions on my disk:

The screenshot is from a tool called ncdu, from where I can delete directories after reviewing the disk usage. But I have noticed that Go has restricted the deletion of these packages by users. If I try to delete api@v0.70.0 but I get “Permission denied” error.

So… how do Go developers manage deletion of all the old packages? Is there a go .. command that does that?

I spent many hours searching for this and found nothing. And finally I posted this question here.

Then I searched a bit more… and finally found the answer!

go clean -modcache


1 Like

I wrote a blog post on this topic: Cleaning up ${GOPATH}/pkg/ ❚ A Scripter's Notes.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.