Open envintus opened 3 years ago
I had the same problem on traditional, non-M1 hardware. Turns out that earlier in my giant .zshrc I was source
'ing GVM. It was setting GOROOT to be an empty string. Once I removed that it worked and my $PATH is back to normal.
Scratch that, I must have had a bad test. I still have the issue.
Same on non-m1 mac.
goenv rehash
does setting the GOROOT
and GOPATH
vars after changing them.
The issue here is export PATH="$GOROOT/bin:$PATH"
. $GOROOT
is evaluated when your .zshrc
is read and not when the PATH
is searched. As such you'll directly call the go binaries instead of using goenv's shims. Remove that from your config and things should work as expected.
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.
I've hit this issue, but if I don't run goenv init -
then goenv doesn't work for me.
My zshrc config is as follows:
# Check for goenv existance and enable it if it's there
[[ -d "${HOME}/.goenv" ]] && export GOENV_ROOT="${HOME}/.goenv"
# Enable goenv things
if [ ! -z "${GOENV_ROOT}" ]; then
export PATH="${GOENV_ROOT}/bin:${PATH}"
eval "$(goenv init -)"
## Commenting these as it breaks the use of `.go-version` files.
#export PATH="${GOROOT}/bin:${PATH}"
#export PATH="${PATH}:${GOPATH}/bin"
fi
Looks like this has been solved.
I just started using the latest version goenv
on my MacBook Pro with an Apple M1 processor, installed via Homebrew, and am having this exact same issue. The shell environment variables $GOPATH
and $GOROOT
are not set when I use
goenv shell <version>
or goenv local <version>
commands. Note -- the version of Go is switched (with the one caveat below) but not the environment variables.
As per @jochman's post above, goenv rehash
will set the variables after switching the version, but I think this should be done automatically?
And like @Nalum, when I follow the install instructions, adding these two lines after eval "$(goenv init -)"
in my .zshrc
breaks the use of .go-version
for local version switching.
export PATH="${GOROOT}/bin:${PATH}"
export PATH="${PATH}:${GOPATH}/bin"
If I remove those two lines local version switching works (but setting the environment variables still doesn't work).
@ChronosMasterOfAllTime -- you marked this issue as resolved back in Feb 19? It does not appear to be resolved, unless I misunderstood the discussion in this thread.
Any help really appreciated.
@ianjukes I will look into this. I also have a a Mac with zsh installed. Let me try to reproduce what you're running into.
Thank you @ChronosMasterOfAllTime. Just let me know if you need me to do any additional troubleshooting.
Did this ever work for you @ianjukes? I am facing the same issue as you
As @ianjukes described I have the same behavior.
As per @jochman's post above,
goenv rehash
will set the variables after switching the version, but I think this should be done automatically?And like @Nalum, when I follow the install instructions, adding these two lines after
eval "$(goenv init -)"
in my.zshrc
breaks the use of.go-version
for local version switching.export PATH="${GOROOT}/bin:${PATH}" export PATH="${PATH}:${GOPATH}/bin"
Using ubuntu with zsh and this is my experience also. The two exports added after the init described in the readme break the .go-version
file switching, and it requires manually running goenv rehash
to update the env vars.
Did this ever work for you @ianjukes? I am facing the same issue as you
Unfortunately not -- I still have the same issue.
@ianjukes please find me on Discord so we can better figure out what's going on
my username is the same as here but all lowercase
I've followed the installation instructions in an attempt to setup
goenv
and have it manage$GOPATH
and$GOROOT
on my Apple M1 MacBook Pro.I'm using ZSH as my shell and this is the contents of my
.zshrc
file.After configuring
.zshrc
and restarting my shell this is what I see for Golang environment variables:For what it's worth I'm able to successfully use
goenv
to install Golang. I also have a non-M1 MacBook Pro that I did the same setup on using ZSH and had no issues with installation and havinggoenv
manage$GOPATH
and$GOROOT
.