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

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 this issue Apr 1, 2024 · 4 comments
Labels
Builders x/build issues (builders, bots, dashboards) FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@sryze
Copy link

sryze commented Apr 1, 2024

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 seankhliao changed the title Installer always adds %USERPROFILE%\go\bin to PATH on Windows despite having GOPATH point to another directory x/build: windows installer always adds %USERPROFILE%\go\bin to PATH despite having GOPATH point to another directory Apr 1, 2024
@gopherbot gopherbot added the Builders x/build issues (builders, bots, dashboards) label Apr 1, 2024
@gopherbot gopherbot added this to the Unreleased milestone Apr 1, 2024
@seankhliao
Copy link
Member

I think this comes from CL 104115

@dmitshur dmitshur changed the title x/build: windows installer always adds %USERPROFILE%\go\bin to PATH despite having GOPATH point to another directory x/build/internal/installer/windowsmsi: Windows installer always adds %USERPROFILE%\go\bin to PATH even if user overrode GOPATH to point to another directory Apr 2, 2024
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 2, 2024
@dmitshur
Copy link
Contributor

dmitshur commented Apr 2, 2024

CC @golang/release.

@dmitshur
Copy link
Contributor

dmitshur commented Apr 2, 2024

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
Copy link
Author

sryze commented Apr 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Builders x/build issues (builders, bots, dashboards) FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
Status: Planned
Development

No branches or pull requests

4 participants