Open huanghantao opened 2 years ago
the same problem. i resolved by comment the following lines, and source ~/.zsh
if above lines are not commented, every time you use 'go local 1.14.4', you should do source ~/.zsh, then go version
will change to what you want. I don't know whether this is a bug.
This is a configuration issue -- you shouldn't be blindly prepending $GOROOT/bin
to the path but instead relying on goenv's shims in your path (which are put there by goenv init -
). goenv local
is doing nothing because the old $GOROOT
from your shell startup is taking precedence over the shims.
It looks like the offending lines came from the README -- it looks like this feature is not that well thought-out and potentially breaks stuff badly. I personally don't use goenv init -
/configure according to the README so I never ran into this.
Yes I think that's because using the *env init -
is the common approach of all the *env
tools. What's your approach @neersighted and more importantly your workflow? I presume that the expectation of goenv
users is for the tool to behave like rbenv
, pyenv
, etc. where changing into a folder with a local override will immediately setup the environment with all the right paths.
I found my way here for this exact reason. Use pyenv on a daily basis so expecting goenv to function similarly. Following the instructions I added this in my zsh setup:
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
if (( $+commands[goenv] )); then
eval "$(goenv init -)"
export PATH="$GOROOT/bin:$PATH"
export PATH="$PATH:$GOPATH/bin"
fi
This results in the same issue OP describes. Removing the exports from my if block like so
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
if (( $+commands[goenv] )); then
eval "$(goenv init -)"
fi
results the correct behavior I was looking for.
❯ which go
/home/me/.goenv/shims/go
❯ goenv versions
* system (set by /home/me/.goenv/version)
1.17.0
❯ go version
go version go1.18.3 linux/amd64
❯ go local 1.17.0
go local: unknown command
Run 'go help' for usage.
❯ goenv local 1.17.0
❯ goenv versions
system
* 1.17.0 (set by /home/me/.go-version)
❯ go version
go version go1.17 linux/amd64
Whats going on guys? We experienced the same issue and we had this in bash as instructed by INSTALL.md
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"
export PATH="$GOROOT/bin:$PATH"
export PATH="$PATH:$GOPATH/bin"
Removing the bottom two line solves the issue, at least it looks like solved for now. What is the correct behavior? If these lines are not needed, then why INSTALL.md tells (and says its recommended) you to add these? @neersighted @debo
Whats going on guys? We experienced the same issue and we had this in bash as instructed by INSTALL.md
export GOENV_ROOT="$HOME/.goenv" export PATH="$GOENV_ROOT/bin:$PATH" eval "$(goenv init -)" export PATH="$GOROOT/bin:$PATH" export PATH="$PATH:$GOPATH/bin"
Removing the bottom two line solves the issue, at least it looks like solved for now. What is the correct behavior? If these lines are not needed, then why INSTALL.md tells (and says its recommended) you to add these? @neersighted @debo
I'm having the same problem and commenting the lines won't fix it for me. I tried to install goenv
via homebrew but still the problem exists.
The go vesion
will update once I update the shell.
❯ go version
go version go1.19.3 darwin/amd64
❯ goenv local 1.19.4
❯ go version
go version go1.19.3 darwin/amd64
❯ exec $SHELL
❯ go version
go version go1.19.4 darwin/amd64
I know i'm kinda necro-bumping, but I fiddled a bit more today and ended up with this in bashrc
export GOENV_ROOT="$HOME/.goenv"
export PATH="$PATH:$GOENV_ROOT/bin"
eval "$(goenv init -)"
unset GOROOT
unset GOPATH
I'm unsetting GOROOT and GOPATH because those values are only set at init. And as I navigate through different go version enabled directories, those env variables becomes wrong, so they become a source of confusion. unsetting them solves the confusion.
As I'm not putting not putting $GOPATH/bin,$GOROOT/bin in PATH, there is no conflict. all go commands are run by goenv shims, shims set the correct GOPATH/GOROOT env just before executing.
Reproducible Steps:
In the same shell:
In the same shell:
other info: