asdf-golang icon indicating copy to clipboard operation
asdf-golang copied to clipboard

Support for the GOBIN environment variable for each Go version.

Open BorzdeG opened this issue 2 years ago • 5 comments

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

BorzdeG avatar Jun 27 '23 06:06 BorzdeG

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

ankitcharolia avatar Aug 26 '23 21:08 ankitcharolia

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

BorzdeG avatar Aug 28 '23 18:08 BorzdeG

@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!

lothar1998 avatar Mar 08 '24 14:03 lothar1998

@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?

ctsstc avatar Apr 05 '24 20:04 ctsstc

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

lothar1998 avatar Jul 10 '24 08:07 lothar1998