I want to know if there is golang way to delete or remove a go package. To be simpler, opposite to go get command.
e.g. $ go get <PACKAGE_NAME> $ go delete <PACKAGE_NAME> (Looking for similar functionality)
Please NOTE that I am aware that we can remove the downloaded files from src and pkg directory manually by using rm command. But the problem is that system command rm is not aware of your go specific stuffs (etc. to look inside $GOPATH/pkg .. ) and this is an extra step for the user while using rm . I am looking for something which all package managers provides.. as mentioned in one comment.. (npm uninstall, pip uninstall etc..).
If you want to remove the packages installed with the go get command – we can directly delete the files/directories related to the installed package. We have to delete the source directory under $GOPATH/src and compiled package file under $GOPATH/pkg/<architecture>.
The packages from the standard library are available at the “pkg” subdirectory of the GOROOT directory. When you install Go, an environment variable GOROOT will be automatically added to your system for specifying the Go installer directory.
Go The Go Command Go Get go get downloads the packages named by the import paths, along with their dependencies. It then installs the named packages, like 'go install'. Get also accepts build flags to control the installation. When checking out a new package, get creates the target directory $GOPATH/src/<import-path> .
go clean -modcache This command is used to clear the mod cache which is stored at $GOPATH/pkg/mod . This command is used to remove the installed packages. The -modcache flag removes the entire module download cache, including unpacked source code of versioned dependencies.
You can just delete it from you disk:
rm -r $GOPATH/src/<PACKAGE_NAME>
This will remove the package completely. Alas, there is no tool or go command for removing packages. But this should be simple enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With