-
Notifications
You must be signed in to change notification settings - Fork 248
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
Switching directories doesn't change go version #294
Comments
I encountered the same issue. I had to remove the last two
for version switch to work, where |
Does that break anything for you? e.g. do any of your Go projects not compile? I don't understand the consequence of having the Have you checked So here's what I've just tried. I comment out the PATH modifications you mention... if [ ! -d "$HOME/.goenv" ]; then
git clone https://github.com/syndbg/goenv.git ~/.goenv
fi
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"
# export PATH="$GOROOT/bin:$PATH"
# export PATH="$PATH:$GOPATH/bin" I then open up a new terminal instance so my
I check So I can see that goenv hasn't affected the Now, running
A I then run
Now that's interesting because I don't recall installing I then run
Now what's really interesting is the following...
...although So yeah goenv is having no actual affect (since commenting out the two PATH modifications) although it internally has configured the right global to be used and otherwise thinks that is what's being used. OK so now, I Not sure why they worked for you 🤔 (at least partially worked for you). |
Here's my workaround that seems to work for me (e.g. re-sourcing the .zshrc every time I change directory)... # Standard configuration...
if [ ! -d "$HOME/.goenv" ]; then
git clone https://github.com/syndbg/goenv.git ~/.goenv
fi
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"
export PATH="$GOROOT/bin:$PATH"
export PATH="$PATH:$GOPATH/bin"
# I already have `cd` and `__zoxide_cd` functions defined
# for running `ls` every time I change directory,
# so now I just add `source ~/.zshrc` to it as well...
function cd {
builtin cd "$@"
RET=$?
ls
source ~/.zshrc
return $RET
}
function __zoxide_cd {
builtin cd "$@"
RET=$?
ls
source ~/.zshrc
return $RET
} |
Nothing breaks, I mentioned this because the two lines I commented out are leveraging these two environment variables which don't seem to be updated by goenv accordingly.
Maybe check whether you configured the
which I think is mandatory for goenv to work correctly. |
@ankitcharolia thanks, I'll try it out. What's the rationale for this fork? Are there significant issues with the current version, and what has been changed in the fork? Thanks |
@Integralist that isn't a fork, rather a whole new implementation relying on a golang-compiled CLI tool using goreleaser. |
Ah, thanks for clarifying. |
Is this the same issue as #186 ? |
Yes, and I believe the same issue as #209 as well The key point being the docs recommend
in your shell RC file, but this means local .go-versions won't work unless you re-source that file every time you change directories. Since the global default GOROOT will be ahead of the shims in your path. |
@Integralist And since it's been almost a year since this issue was first reported, I'm wondering why it still hasn't been fixed. |
@dicebattle this is my approach now https://github.com/Integralist/dotfiles/blob/main/.zshrc#L574-L596 https://github.com/Integralist/dotfiles/blob/main/.zshrc#L517-L527 Again, not perfect but does the job better than before |
👋🏻
I use https://www.warp.dev/ with a Zsh shell and a https://starship.rs/ prompt (I also use Zoxide for switching directories but the reported issue happens even with standard
cd
).I'm finding that when I switch between project directories (where each project has its own
.go-version
file and are set with different Go versions), that changing directory doesn't trigger thego
binary to be the expected version.Here is my
~/.zshrc
configuration:At the time of reporting this issue, I'm using the latest release:
If I open up a new terminal instance at my home directory
~/
and runwhich go
I see:This aligns with
goenv global
.Now if I
cd
into a project directory with a.go-version
file containing1.20.2
and re-rungo version
I'll still see the global Go1.20.0
being used. If I reload my shell scripts (e.g.source ~/.zshrc
) then running bothwhich go
andgo version
will now report the expected1.20.2
version.Now if I
cd
into another project with a.go-version
file containing1.18.5
and re-rungo version
I'll still see the previous Go version1.20.2
being used. If I reload my shell scripts (e.g.source ~/.zshrc
) then running bothwhich go
andgo version
will now report the expected1.18.5
version.The text was updated successfully, but these errors were encountered: