Go: doc: mention how to add GOPATH\bin to PATH for Windows users

Created on 9 Jan 2017  路  11Comments  路  Source: golang/go

GOPATH variable section is not mentioning that GOPATH\bin needs to be added to PATH for convince. Create a wiki page with platform specific instructions how to add the bin directory to the PATH and add instructions for Windows.

Documentation FrozenDueToAge NeedsFix OS-Windows

Most helpful comment

Thanks @alexbrainman that is it.

Specifically, this line: https://github.com/golang/build/blob/master/cmd/release/releaselet.go#L732

By changing that line from this

Value="%GOPATH%\bin" />

to this instead

Value="%USERPROFILE%\go\bin" />

then the MSI installer modifies the PATH correctly, and no further effort is required from the user.

Otherwise, the user must open the "Control Panel -> Edit environment variables for your account" from the "Start" menu and click on the "OK" button in the dialog. Once this has been done, the user can open a new command window, and the path will be set correctly.

The above is via http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Setting-environment-variable-PATH-tp2418484p5264135.html

All 11 comments

We need to stop adding stuff to Go 1.8. Let's target Go 1.9.

The Windows installer does this automatically, so maybe this isn't required?

See: https://golang.org/doc/install?download=go1.8.3.windows-amd64.msi

Screen capture of the page at 7 June 2017:

screen shot 2017-06-07 at 10 10 18

@a-h Maybe I'm mistaken, but GOPATH\bin is not c:\Go\bin?

Yes, you're right. On Windows %GOPATH%\bin is %USERPROFILE%\go, so if your Windows Username is Administrator, then your GOPATH would be C:\Users\Administrator\Go by default.

For Windows, I checked what happens if you install Go 1.10.2 on a new Windows Server 2016 VM running in AWS.

I can see that %GOPATH%\bin is added to the path by the installer by default:

screen shot 2018-05-25 at 14 47 41

So, for Windows, no documentation improvement is probably needed, I don't know whether the installation process for Linux or MacOS include this helpful step though.

Very strange, for me that Path was not added it seems @a-h

I have two points of measurement, one from a few months back, so that might not be accurate anymore. But I also installed go very recently on a new machine, with no %GOPATH%\bin in fact.
I have to say though, I installed using chocolatey, so maybe my experience is different.

Just ran the MSI install of Go 1.10.3 on a clean Win10 VM. Although %GOPATH%\bin is added and appears in the list of paths in the editor, it does not get expanded correctly to the value of the GOPATH variable, probably due to missing ending semi-colon ala https://serverfault.com/questions/300544/environment-variables-in-path-not-expanded-for-non-admin-command-prompt#300591

The result of this is that go install and friends run correctly, however the resulting binary files are not in the Windows path and so cannot be run from any directory besides where the .exe file is located.

If someone could kindly point me towards where the script that builds the MSI file is located, I'd be happy to take a look.

If someone could kindly point me towards where the script that builds the MSI file is located

I think you want $GOPATH/src/golang.org/x/build/cmd/release/releaselet.go

Alex

Thanks @alexbrainman that is it.

Specifically, this line: https://github.com/golang/build/blob/master/cmd/release/releaselet.go#L732

By changing that line from this

Value="%GOPATH%\bin" />

to this instead

Value="%USERPROFILE%\go\bin" />

then the MSI installer modifies the PATH correctly, and no further effort is required from the user.

Otherwise, the user must open the "Control Panel -> Edit environment variables for your account" from the "Start" menu and click on the "OK" button in the dialog. Once this has been done, the user can open a new command window, and the path will be set correctly.

The above is via http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Setting-environment-variable-PATH-tp2418484p5264135.html

Change https://golang.org/cl/127777 mentions this issue: cmd/release: use %USERPROFILE% instead of %GOPATH% in PATH

By changing that line from this

Value="%GOPATH%\bin" />
to this instead

Value="%USERPROFILE%\go\bin" />

Done. Please, review my change https://go-review.googlesource.com/c/build/+/127777.

Alex

The GOPATH section now mentions adding GOPATH/bin and it links to https://github.com/golang/go/wiki/SettingGOPATH#windows which has instruction on how to do so on windows; so this is fixed. Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dominikh picture dominikh  路  3Comments

jayhuang75 picture jayhuang75  路  3Comments

Miserlou picture Miserlou  路  3Comments

bradfitz picture bradfitz  路  3Comments

natefinch picture natefinch  路  3Comments