kevincobain2000 / gobrew

Go version manager, written in Go. Super simple tool to install and manage Go versions. Install go without root. Gobrew doesn't require shell rehash.
https://medium.com/web-developer/go-version-manager-gobrew-c8750157dfe6
MIT License
364 stars 24 forks source link

What is the best value for $GOPATH #97

Closed shotexa closed 1 year ago

shotexa commented 1 year ago

Hello, I'm new to go so please excuse me if it is a noob question.

I've installed go via gobrew, I like it for its simplicity over other go version managers. When I'm trying to use vsCode, it asks me to install gopls (go language server) for it to run via the command go install golang.org/x/tools/gopls@latest, which has installed it in $HOME/go and the binary is located in $HOME/go/bin/gopls which is not on the $PATH. According to go install manual (go help install):

Executables are installed in the directory named by the GOBIN environment
variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH
environment variable is not set. Executables in $GOROOT
are installed in $GOROOT/bin or $GOTOOLDIR instead of $GOBIN.

Since $GOPATH is not defined, it has installed the executable in $HOME/go/bin. I think go version manager should manage this aspect as well. Is this something that is planned? and where would you suggest pointing $GOPATH?

kevincobain2000 commented 1 year ago

Thanks for your question. GOPATH is a go thing, and gobrew can be isolated from this responsibility. It is not possible for gobrew to manage that path, as you can set it up using env var in your ~/.bashrc. My GOPATH is set to the default default one by go

╰─$ go env|grep -i gopath
GOPATH="/Users/pulkit.kathuria/go"
╰─$ which gopls
/Users/pulkit.kathuria/go/bin/gopls

Actually you can set GOROOT and GOPATH by yourself as envs and gobrew doesn't need to know about it.

I think @juev can articulate it better than me on this.

juev commented 1 year ago

Hello!

You don’t need to set GOROOT, really, but for gobrew is it main point.

How to Write Go Code (with GOPATH) describes what the GOPATH variable is used for and what default values are used. It defaults to a directory named go inside your home directory, so $HOME/go on Unix, $home/go on Plan 9, and %USERPROFILE%\go (usually C:\Users\YourName\go) on Windows.

If you want, you can change this value to different location.