rodrigocfd
rodrigocfd

Reputation: 8068

Completely remove a package installed with "go get"?

I'm using Go 1.13.1, latest as of today.

I'm trying to completely remove a package that I installed with go get from GitHub. The go clean -i <PACKAGE_NAME> didn't seem to work, since there are files spread through, at least, these directories:

~/go/pkg/mod/github.com/<PACKAGE_NAME>
~/go/pkg/mod/cache/download/github.com/<PACKAGE_NAME>
~/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/github.com/<PACKAGE_NAME>

Is there a way to clean everything without removing all that manually?

Upvotes: 30

Views: 94435

Answers (2)

Bala555
Bala555

Reputation: 189

We can remove cache for one or multiple packages from GOPATH easily.

  1. Delete go.sum file in your project root folder.
  2. Delete vcs folder in GOPATH/pkg/mod/cache.
  3. Delete all files of your library in GOPATH/pkg/mod/cache/download/{Package_name}/{library_name} or remove files ({version_to_delete}.*) belongs to specific version and update list file.
  4. Delete specific version of library in GOPATH/pkg/mod/{Package_name}/{library_name}@{version}.
  5. Now, run go mod tidy in your project root folder. It should download library from the internet instead of respawing from local cache.

Upvotes: 5

icza
icza

Reputation: 418435

This is currently not supported. If you think about it: it may be the current module does not need it anymore, but there may be other (unrelated) modules on your system that may still need it. The module cache is "shared" between all the modules on your system; it can be shared because dependencies are versioned, and if 2 unrelated modules refer to the same version of a module / package, it's the same and can be shared.

The closest is go clean with -modcache, but that removes the entire module cache:

The -modcache flag causes clean to remove the entire module download cache, including unpacked source code of versioned dependencies.

Upvotes: 55

Related Questions