asdf-community / asdf-golang

Go plugin for the asdf version manager
https://github.com/asdf-vm/asdf
MIT License
530 stars 88 forks source link

Support for the GOBIN environment variable for each Go version. #107

Closed BorzdeG closed 2 weeks ago

BorzdeG commented 1 year ago

By default, if GOBIN is not set, it is not guaranteed that the path $GOPATH/bin will be used - it is better to set it explicitly in the Environment

ankitcharolia commented 1 year ago

@BorzdeG Kindly try out this goenv: https://github.com/ankitcharolia/goenv

BorzdeG commented 1 year ago

@ankitcharolia Why install something else when it can be solved with one utility?

lothar1998 commented 6 months ago

@BorzdeG

I feel like modifying the set-env.zsh script can help (of course for ZSH):

asdf_update_golang_env() {
  local go_path
  go_path="$(asdf which go)"
  if [[ -n "${go_path}" ]]; then
    export GOROOT
    GOROOT="$(dirname "$(dirname "${go_path:A}")")"

    # the next two lines should be added to the original script
    export GOBIN
    GOBIN="$(dirname "$(dirname "${go_path:A}")")/bin"
  fi
}

autoload -U add-zsh-hook
add-zsh-hook precmd asdf_update_golang_env

This modification worked for me. Please let me know your thoughts!

ctsstc commented 5 months ago

@lothar1998 this is what I was just about to do, but wanted to see what others were doing or if I was the only one with this issue. I ran go env and my GOBIN is an empty string. I'm still not certain where go install is installing to if it's an empty string 🤷 I thought it was supposed to default off of the GOROOT, but that seems it may not be the case?

lothar1998 commented 1 month ago

@ctsstc It seems that it installs the binary into $GOROOT/bin so I believe the fix I proposed should help. Please take a look at https://github.com/asdf-community/asdf-golang/pull/139.