DEV Community 👩‍💻👨‍💻

Cover image for Check if go package installed + "uninstall go package"
hzoltan
hzoltan

Posted on • Updated on

Check if go package installed + "uninstall go package"

#go

In a directory where there is a go.mod file, you can discover the install path:

$ go list -f '{{.Target}}'
Enter fullscreen mode Exit fullscreen mode

I don't come up with this, just found it at https://golang.org/doc/tutorial/compile-install .

One liner:

$ go list -f '{{.Target}}' | if xargs ls -la &> /dev/null ; then echo "Installed"; else echo "Not installed"; fi
// Outputs "Installed" or "Not installed"
Enter fullscreen mode Exit fullscreen mode

Remove it:

$ go clean -i
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

🌚 Life is too short to browse without dark mode