I ran go get package
to download a package before learning that I needed to set my GOPATH
otherwise that package sullies my root Go install (I would much prefer to keep my Go install clean and separate core from custom). How do I remove packages installed previously?
相关问题
- Golang mongodb aggregation
- How to flatten out a nested json structure in go
- how to install private repo using glide golang
- How to convert a string to a byte array which is c
- IntelliJ 2017.1.2 GOLANG debug does not work on br
It's safe to just delete the source directory and compiled package file. Find the source directory under
$GOPATH/src
and the package file under$GOPATH/pkg/<architecture>
, for example:$GOPATH/pkg/windows_amd64
.You can delete the archive files and executable binaries that
go install
(orgo get
) produces for a package withgo clean -i importpath...
. These normally reside under$GOPATH/pkg
and$GOPATH/bin
, respectively.Be sure to include
...
on the importpath, since it appears that, if a package includes an executable,go clean -i
will only remove that and not archive files for subpackages, likegore/gocode
in the example below.Source code then needs to be removed manually from
$GOPATH/src
.go clean
has an-n
flag for a dry run that prints what will be run without executing it, so you can be certain (seego help clean
). It also has a tempting-r
flag to recursively clean dependencies, which you probably don't want to actually use since you'll see from a dry run that it will delete lots of standard library archive files!A complete example, which you could base a script on if you like:
Note that this information is based on the
go
tool in Go version 1.5.1.For those using Go 1.11 modules, all you have to do is run
go mod tidy
. From the golang wiki:Usage: