golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.88k stars 17.52k forks source link

x/build/internal/installer/windowsmsi: Windows installer always adds %USERPROFILE%\go\bin to PATH even if user overrode GOPATH to point to another directory #66633

Open sryze opened 5 months ago

sryze commented 5 months ago

Go version

go version go1.22.1 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=E:\Caches\go\cache
set GOENV=C:\Users\user\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=E:\Tools\Go\gopath\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\Tools\Go\gopath
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=E:\Caches\go\tmp
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=E:\Caches\go\tmp\go-build937642864=/tmp/go-build -gno-record-gcc-switches

What did you do?

  1. Install Go on Windows via the MSI installer
  2. Open environment variables settings and observe the value of the user's PATH variable

What did you see happen?

Despite that I have GOPATH=E:\Tools\Go\gopath and E:\Tools\Go\gopath\bin is present in my PATH, the installer still appends the default value %USERPROFILE%\go\bin to my PATH.

What did you expect to see?

Expected to not have PATH modified by the installer.

At the very least, it should ask if the user would like to add %GOPATH%\bin to PATH during installation, similar to how other software does it, e.g. OpenJDK (Eclipse Temurin) does that.

seankhliao commented 5 months ago

I think this comes from CL 104115

dmitshur commented 5 months ago

CC @golang/release.

dmitshur commented 5 months ago

The Windows installer currently always takes responsibility for setting the GOPATH environment variable (to %USERPROFILE%\go) and adding %GOPATH%/bin to PATH. If a user wishes to use a different location, they need to override both of those. (Note that this is different from the macOS installer, which currently doesn't take responsibility for GOPATH, leaving it entirely to the user. Though different in behavior to each other, both installers have been consistent in their according behavior for a while.)

It seems this is a feature request to make it possible to opt out of this behavior in the Windows installer, so if a user wishes to pick a different GOPATH location, they can do it in a better way than forcibly overriding both GOPATH and PATH environment variables after the installer completed.

sryze commented 5 months ago

While you're at it, perhaps adding the Go installation directory (C:\Program Files\Go) to PATH should also be made a checkbox (checked by default)? So it could look something like this:

[V] Add Go to PATH [V] Add GOPATH\bin to PATH

or they could be merged into one:

[V] Add Go and GOPATH\bin to PATH

Below are some examples from other popular packages:

Node: node-installer

Java: java-installer

Python: python-installer