Skip to content

In Windows images, env var 'GOPATH' points to empty folder. #288

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

Closed
ob1dev opened this issue Jul 9, 2019 · 6 comments
Closed

In Windows images, env var 'GOPATH' points to empty folder. #288

ob1dev opened this issue Jul 9, 2019 · 6 comments

Comments

@ob1dev
Copy link

ob1dev commented Jul 9, 2019

It seems like all Windows images has the same issue. The environment variable GOPATH points to the path C:\gopath, but there is nothing inside this directory.

# ideally, this would be C:\go to match Linux a bit closer, but C:\go is the recommended install path for Go itself on Windows
ENV GOPATH C:\\gopath

The reason because Golang is installed into the path C:\go.

RUN $url = ('https://golang.org/dl/go{0}.windows-amd64.zip' -f $env:GOLANG_VERSION); \
Write-Host ('Downloading {0} ...' -f $url); \
Invoke-WebRequest -Uri $url -OutFile 'go.zip'; \
\
$sha256 = '502712c0e29edc6b9cda6fa5e4b6ff9b36e27d225373baead8708c9634aa8e50'; \
Write-Host ('Verifying sha256 ({0}) ...' -f $sha256); \
if ((Get-FileHash go.zip -Algorithm sha256).Hash -ne $sha256) { \
Write-Host 'FAILED!'; \
exit 1; \
}; \
\
Write-Host 'Expanding ...'; \
Expand-Archive go.zip -DestinationPath C:\; \
\
Write-Host 'Verifying install ("go version") ...'; \
go version; \
\
Write-Host 'Removing ...'; \
Remove-Item go.zip -Force; \
\
Write-Host 'Complete.';

Shouldn't GOPATH points to C:\go?

@tianon
Copy link
Member

tianon commented Jul 9, 2019

GOPATH is where your source code belongs (unless you're using Go Modules).

I believe you're thinking of GOROOT (which is supposed to point to the Go installation and we don't set it because Go itself detects the correct value appropriately).

@tianon
Copy link
Member

tianon commented Jul 9, 2019

See https://github.com/golang/go/wiki/GOPATH for additional useful details on this.

@ob1dev
Copy link
Author

ob1dev commented Jul 14, 2019

@tianon, right I mixed GOROOT with GOPATH, but it's still a bit confusing that

  • on Linux:

    • the environment variable GOROOT points to /usr/local/go
    • the environment variable GOPATH points to /Users/<user-name-here>/go
  • on Windows:

    • the environment variable GOROOT points to C:\Go
    • the environment variable GOPATH points to C:\Users\<user-name-here>\go
  • in Linux container:

    • the environment variable GOROOT points to /usr/local/go
    • the environment variable GOPATH points to /go
  • in Windows container:

    • the environment variable GOROOT points to C:\go
    • the environment variable GOPATH points to C:\gopath

I think the root issue comes from the Go Team (golang/go#23848) when they decided to install the source for Go projects and their binaries (GOROOT) into the root of system drive (C:\). It's not where I would expect it to get installed on Windows. The right place would be C:\Program Files\Go (GOROOT). Then inside Windows container it would looks like:

  • the environment variable GOROOT points to C:\Program Files\Go
  • the environment variable GOPATH points to C:\go

As an example, Microsoft installs .NET Core (OSS) using the following locations:

  • in Linux container /usr/share/dotnet, see here for details.
  • in Windows container C:\Program Files\dotnet, see here for details.

@tianon
Copy link
Member

tianon commented Sep 6, 2019

So, I get that this is confusing, but what I'm not getting is what harm this causes? The GOPATH environment variable is set appropriately (usable both for things like $GOPATH/src/... and go get to pick up automatically), and GOROOT is not set at all (the go tool figures out the appropriate value automatically). If the exact value of these are needed, that's what go env XXX is for (and for many users running Go on their host, the values of these will vary wildly depending on their personal preferences, how they obtained Go, etc so any scripts needing these variables would have to tolerate them being very different).

@wglambert
Copy link

Going to close since this seems resolved

@tianon
Copy link
Member

tianon commented Jul 16, 2021

As a bit of a necro-update, I've filed #377 to change this in Go 1.17+ (now that it's changed in Go's installers and we have an upstream version to toggle on for a minor backwards compat break).

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

3 participants