Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goenv not setting $GOPATH and $GOROOT on Apple M1 using ZSH #186

Open
envintus opened this issue Jul 18, 2021 · 15 comments
Open

goenv not setting $GOPATH and $GOROOT on Apple M1 using ZSH #186

envintus opened this issue Jul 18, 2021 · 15 comments

Comments

@envintus
Copy link

envintus commented Jul 18, 2021

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.

export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"
export PATH="$GOROOT/bin:$PATH"
export PATH="$PATH:$GOPATH/bin"

After configuring .zshrc and restarting my shell this is what I see for Golang environment variables:

$ env | grep GO | sort
GOENV_ROOT=/Users/hsatterwhite/.goenv
GOENV_SHELL=zsh

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 having goenv manage $GOPATH and $GOROOT.

@derekcrovo
Copy link

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.

@derekcrovo
Copy link

Scratch that, I must have had a bad test. I still have the issue.

@jochman
Copy link

jochman commented Nov 11, 2021

Same on non-m1 mac.
goenv rehash does setting the GOROOT and GOPATH vars after changing them.

@neersighted
Copy link
Contributor

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.

@neersighted
Copy link
Contributor

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.

@Nalum
Copy link

Nalum commented Aug 17, 2022

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

@ChronosMasterOfAllTime
Copy link
Collaborator

Looks like this has been solved.

@ianjukes
Copy link

ianjukes commented Oct 10, 2023

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.

@ChronosMasterOfAllTime
Copy link
Collaborator

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

@ianjukes
Copy link

Thank you @ChronosMasterOfAllTime. Just let me know if you need me to do any additional troubleshooting.

@rahul-r-modi
Copy link

Did this ever work for you @ianjukes? I am facing the same issue as you

@chriscarpenter12
Copy link

chriscarpenter12 commented Nov 9, 2023

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.

@ianjukes
Copy link

Did this ever work for you @ianjukes? I am facing the same issue as you

Unfortunately not -- I still have the same issue.

@ChronosMasterOfAllTime
Copy link
Collaborator

@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

@oneWalker
Copy link

If you're using homebrew in your M1 mac and the data is imported from an Intel one, you can consider removing /usr/local/Cellar/go. Because the package installed in the previous one, can still be applied to the whole machine when the new package doesn't exist in the new homebrew-installed location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants