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

The go env cannot be overwrite by the env #68864

Closed
jianzhangbjz opened this issue Aug 14, 2024 · 4 comments
Closed

The go env cannot be overwrite by the env #68864

jianzhangbjz opened this issue Aug 14, 2024 · 4 comments

Comments

@jianzhangbjz
Copy link

Go version

go version go1.21.9 darwin/arm64

Output of go env in your module/workspace:

$ go env 
GO111MODULE=''
GOARCH='arm64'
GOBIN='/Users/jiazha/golang/go1.21/bin'
GOCACHE='/Users/jiazha/Library/Caches/go-build'
GOENV='/Users/jiazha/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/jiazha/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/jiazha/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/jiazha/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.0.darwin-arm64'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/jiazha/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.0.darwin-arm64/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/jiazha/goproject/openshift-tests-private/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/5n/w9ysf4w93jnfy7k19xxct31c0000gn/T/go-build62998153=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

The go version outputs wrong version,

jiazha-mac:openshift-tests-private jiazha$ go version
go version go1.22.0 darwin/arm64
jiazha-mac:openshift-tests-private jiazha$ which go 
/Users/jiazha/golang/go1.21/bin/go
```the 

### What did you see happen?

I checked the ENV, the `GOROOT=/Users/jiazha/golang/go1.21`, however, the `GOROOT='/Users/jiazha/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.0.darwin-arm64'` in the `go env`, as follows,
```console
jiazha-mac:openshift-tests-private jiazha$ export GOROOT=/Users/jiazha/golang/go1.21
jiazha-mac:openshift-tests-private jiazha$ env |grep GOROOT
GOROOT=/Users/jiazha/golang/go1.21

jiazha-mac:openshift-tests-private jiazha$ go env|grep GOROOT
GOROOT='/Users/jiazha/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.0.darwin-arm64'

What did you expect to see?

I can overwrite the GOROOT of go env.

@jianzhangbjz
Copy link
Author

I can get the right outputs after changing the GOTOOLCHAIN='auto' to GOTOOLCHAIN='go1.21.9', as follows, however, it's really confusing why the env cannot overwrite the go env.

jiazha-mac:openshift-tests-private jiazha$ export GOTOOLCHAIN='go1.21.9'
jiazha-mac:openshift-tests-private jiazha$ 
jiazha-mac:openshift-tests-private jiazha$ go version
go version go1.21.9 darwin/arm64
jiazha-mac:openshift-tests-private jiazha$ which go 
/Users/jiazha/golang/go1.21/bin/go

@jianzhangbjz jianzhangbjz changed the title go version outputs wrong version due to the go env cannot be overwrite by the env The go env cannot be overwrite by the env Aug 14, 2024
@seankhliao
Copy link
Member

This is expected for automatic toolchain upgrades from go.mod

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2024
@zigo101
Copy link

zigo101 commented Aug 14, 2024

It is the design. And it is really confused.

The 1.21 go command will search newer enough toolchain versions and call their "go" command instead.
The confusion comes from the fact that the whole process is implicit.

If you want to choose a Go toolchain version explicitly, you can try GoTV.

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

4 participants