Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove an installed package using go modules

Tags:

go

vgo

go-modules

I've installed a package using go modules (go get in Go 1.13) and now I want to remove it. In the documentation there is nothing about this and in go get docu neither.

Removing the package from go.mod manually doesn't solve the issue so it remains in go.sum.

How should I remove a package in a clean way?

like image 864
jesugmz Avatar asked Jul 24 '19 15:07

jesugmz


People also ask

How do you remove package installed with Go install?

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>.

How do I uninstall a package without removing dependencies?

The first “rpm -qa” lists all RPM packages and the grep finds the package you want to remove. Then you copy the entire name and run the “rpm -e –nodeps” command on that package. It will, without prompting for confirmation, remove that package but none of its dependencies.


1 Answers

Found it https://go.dev/blog/using-go-modules#removing-unused-dependencies

go mod tidy

So basically, once the package is not being imported in any package you can perform a go mod tidy and it will safely remove the unused dependencies.

And if you are vendoring the dependencies, then run the command below to make the module changes be applied in the vendor folder:

go mod vendor

like image 176
jesugmz Avatar answered Sep 24 '22 10:09

jesugmz