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

cmd/go: mkdir C:\Program Files\Go: Access is denied. #44691

Closed
Jassi10000-zz opened this issue Feb 28, 2021 · 18 comments
Closed

cmd/go: mkdir C:\Program Files\Go: Access is denied. #44691

Jassi10000-zz opened this issue Feb 28, 2021 · 18 comments
Labels
Milestone

Comments

@Jassi10000-zz
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.16 windows/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\dell\AppData\Local\go-build
set GOENV=C:\Users\dell\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Go\bin\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Go\bin
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\dell\AppData\Local\Temp\go-build2310080819=/tmp/go-build -gno-record-gcc-switches

What did you do?

I tried to install all the necessary modules for Go to setup in VS-Code , as I was preparing to make a project with GoLang

What did you expect to see?

I expected to see all the Go tools properly setup , and after that smooth functioning in VS-Code

What did you see instead?

gopls: failed to install gopls(golang.org/x/tools/gopls): Error: Command failed: c:\go\bin\go.exe get -v golang.org/x/tools/gopls
go: writing stat cache: mkdir C:\Program Files\Go: Access is denied.
go: writing stat cache: mkdir C:\Program Files\Go: Access is denied.
go: downloading golang.org/x/tools/gopls v0.6.6
go: writing go.mod cache: mkdir C:\Program Files\Go: Access is denied.
go: downloading golang.org/x/tools v0.1.0
go get golang.org/x/tools/gopls: mkdir C:\Program Files\Go: Access is denied.
no output

@seankhliao seankhliao changed the title Go is giving unnecessary errors even after fresh installation x/tools/gopls: mkdir C:\Program Files\Go: Access is denied. Feb 28, 2021
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Feb 28, 2021
@gopherbot gopherbot added this to the Unreleased milestone Feb 28, 2021
@stamblerre stamblerre changed the title x/tools/gopls: mkdir C:\Program Files\Go: Access is denied. cmd/go: mkdir C:\Program Files\Go: Access is denied. Mar 3, 2021
@stamblerre stamblerre added GoCommand cmd/go and removed Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Mar 3, 2021
@stamblerre
Copy link
Contributor

@jayconrod @matloob @bcmills can you please take a look? I'm not sure what the advice is for troubleshooting permissions issues

@dmitshur
Copy link
Contributor

dmitshur commented Mar 3, 2021

I think a good next step here would be to determine if Go is installed properly and it's able to build programs. For example, does the go run . command in step 4 of https://golang.org/doc/tutorial/getting-started get you expected output?

The installed path changed recently in #42070 (CC @toothrot), but I don't think that should be causing this. It seems like the GOPATH directory may be misconfigured, possibly from a left-over previous installation.

@dmitshur
Copy link
Contributor

dmitshur commented Mar 3, 2021

The go env output includes:

set GOPATH=C:\Go\bin

That probably needs to be changed.

@bcmills
Copy link
Contributor

bcmills commented Mar 3, 2021

The writing stat cache error comes from here:

fmt.Fprintf(os.Stderr, "go: writing stat cache: %v\n", err)

That implies that the path from that error message is in the module cache, which defaults to %GOPATH%\pkg\mod.

The user-reported go env output shows:

set GOMODCACHE=C:\Go\bin\pkg\mod
…
set GOPATH=C:\Go\bin

So whatever generated that error message is using a different value for GOPATH and/or GOMODCACHE, probably C:\Program Files\Go or similar instead of C:\Go\bin as reported.

@bcmills
Copy link
Contributor

bcmills commented Mar 3, 2021

So, what we need to know now is: what was the actual go command that generated that error message?

(Independently, setting GOPATH to C:\Go\bin seems very suspicious: GOPATH contains its own bin subdirectory at %GOPATH%\bin, so probably you want GOPATH set to C:\Go instead.)

@Jassi10000-zz
Copy link
Author

So all you respected peeps , who are actually helping with the doubt, first of all thank you but what I want is : Can any one of you can tell me the clean precise steps I should finally do ?

@hyangah
Copy link
Contributor

hyangah commented Mar 3, 2021

@Jassi10000 Did you install go using the official Windows go installer? I don't know why the extension picked c:\go\bin\go.exe for go1.16.

If you have a previous version of go.exe installed there, please uninstall/delete C:\Go directory and reinstall using the official windows installed. go1.16 should be installed in C:\Program Files\Go\bin.

@Jassi10000-zz
Copy link
Author

@Jassi10000 Did you install go using the official Windows go installer? I don't know why the extension picked c:\go\bin\go.exe for go1.16.

If you have a previous version of go.exe installed there, please uninstall/delete C:\Go directory and reinstall using the official windows installed. go1.16 should be installed in C:\Program Files\Go\bin.

yes sir , I did that exactly same , that's why second time I changes the file directory , I think that was my only mistake ,
Ok I think I should try again with the steps you mentioned

@dmitshur
Copy link
Contributor

dmitshur commented Mar 3, 2021

You can find instructions to uninstall a previous version at https://golang.org/doc/manage-install#uninstalling, and instructions to install a new version at https://golang.org/doc/install.

See https://golang.org/help/ for more places to get help. I'll close this issue since it doesn't seem to be a bug in the Go project.

@dmitshur dmitshur closed this as completed Mar 3, 2021
@AliPeeri
Copy link

AliPeeri commented Jul 6, 2021

H

What version of Go are you using (go version)?

$ go version
go version go1.16 windows/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output

What did you do?

I tried to install all the necessary modules for Go to setup in VS-Code , as I was preparing to make a project with GoLang

What did you expect to see?

I expected to see all the Go tools properly setup , and after that smooth functioning in VS-Code

What did you see instead?

gopls: failed to install gopls(golang.org/x/tools/gopls): Error: Command failed: c:\go\bin\go.exe get -v golang.org/x/tools/gopls
go: writing stat cache: mkdir C:\Program Files\Go: Access is denied.
go: writing stat cache: mkdir C:\Program Files\Go: Access is denied.
go: downloading golang.org/x/tools/gopls v0.6.6
go: writing go.mod cache: mkdir C:\Program Files\Go: Access is denied.
go: downloading golang.org/x/tools v0.1.0
go get golang.org/x/tools/gopls: mkdir C:\Program Files\Go: Access is denied.
no output

is the issue solved ? because i have found a way to solve it.

@TUSHAR4541
Copy link

@AliPeeri no it's not

@Davo36
Copy link

Davo36 commented Aug 4, 2021

I had this error after installing Go just now. I ran VS Code in Administrator mode and it all went away... So for me I'm pretty sure it was a Windows permissions problem.

@AdamMK
Copy link

AdamMK commented Sep 8, 2021

Had the same issue and resolved it with what @Davo36 did.

@Davo36
Copy link

Davo36 commented Sep 8, 2021

Had the same issue and resolved it with what @Davo36 did.

@AdamMK : Actually I had this again recently and I found the problem to be that I had my GOPATH variable set incorrectly. I describe that here: #26814

Go down to the bottom to see what I did. I had 2 values for the GOPATH variable when viewing in the environment variables dialog box on Windows.

But it did look very much like a Windows permissions problem since Administrator mode makes it go away.

@HoytRen
Copy link

HoytRen commented Dec 8, 2021

I don't think this issue is resolved. I install go with go1.17.3.windows-amd64.msi, and I still see the default repo path is "C:\Program Files\Go\src", then we will sure get the error because of the Windows protection. The repo should be in C:\Users\XXXX\ by default but not in C:\Program Files, just as maven, nodejs and many others did. Ask for admin privilege doesn't make sense at all.

@jackgxl
Copy link

jackgxl commented Dec 14, 2021

Tools environment: GOPATH=D:\code_go, GOBIN=D:\go\bin
Installing 10 tools at the configured GOBIN: D:\go\bin in module mode.
gopkgs
go-outline
gotests
gomodifytags
impl
goplay
dlv
dlv-dap
staticcheck
gopls

Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest (D:\go\bin\gopkgs.exe) SUCCEEDED
Installing github.com/ramya-rao-a/go-outline@latest (D:\go\bin\go-outline.exe) SUCCEEDED
Installing github.com/cweill/gotests/gotests@latest (D:\go\bin\gotests.exe) SUCCEEDED
Installing github.com/fatih/gomodifytags@latest (D:\go\bin\gomodifytags.exe) SUCCEEDED
Installing github.com/josharian/impl@latest (D:\go\bin\impl.exe) SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay@latest (D:\go\bin\goplay.exe) SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv@latest (D:\go\bin\dlv.exe) SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv@master (D:\go\bin\dlv-dap.exe) SUCCEEDED
Installing honnef.co/go/tools/cmd/staticcheck@latest (D:\go\bin\staticcheck.exe) SUCCEEDED
Installing golang.org/x/tools/gopls@latest (D:\go\bin\gopls.exe) SUCCEEDED

All tools successfully installed. You are ready to Go. :)

make sure your GOPATH GOROOT GOBIN GOPROXY are all correct !

@jackgxl
Copy link

jackgxl commented Dec 14, 2021

go env -w GOPROXY=https://goproxy.io,direct
go env -w GOROOT=D:\go
go env -w GO111MODULE=on
go env -w GOBIN=D:\go\bin\go.exe
go env -w GOPATH=D:\code_go

@bcmills
Copy link
Contributor

bcmills commented Dec 14, 2021

This issue is closed. If you are seeing similar symptoms, please file a new issue and fill out the complete template. Thanks.

@bcmills bcmills reopened this Dec 14, 2021
@bcmills bcmills closed this as completed Dec 14, 2021
@golang golang locked as resolved and limited conversation to collaborators Dec 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests