WSL2 Golang install tools: Permission denied

2.8k views Asked by At

I am trying to install the golang tools in WSL2/Ubuntu in order to use them with VSCode. Every time I want to install them via VSCode I get the permission denied message:

Tools environment: GOPATH=/go
Installing 17 tools at /go/bin in module mode.
  gocode
  gopkgs
  go-outline
  go-symbols
  guru
  gorename
  gotests
  gomodifytags
  impl
  fillstruct
  goplay
  godoctor
  dlv
  gocode-gomod
  godef
  goformat
  golint

Installing github.com/mdempsky/gocode FAILED
Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/acroca/go-symbols FAILED
Installing golang.org/x/tools/cmd/guru FAILED
Installing golang.org/x/tools/cmd/gorename FAILED
Installing github.com/cweill/gotests/... FAILED
Installing github.com/fatih/gomodifytags FAILED
Installing github.com/josharian/impl FAILED
Installing github.com/davidrjenni/reftools/cmd/fillstruct FAILED
Installing github.com/haya14busa/goplay/cmd/goplay FAILED
Installing github.com/godoctor/godoctor FAILED
Installing github.com/go-delve/delve/cmd/dlv FAILED
Installing github.com/stamblerre/gocode FAILED
Installing github.com/rogpeppe/godef FAILED
Installing winterdrache.de/goformat/goformat FAILED
Installing golang.org/x/lint/golint FAILED

17 tools failed to install.

gocode: failed to install gocode(github.com/mdempsky/gocode): Error: Command failed: /usr/local/go/bin/go get -v github.com/mdempsky/gocode
go: downloading github.com/mdempsky/gocode v0.0.0-20200405233807-4acdcbdea79d
go get github.com/mdempsky/gocode: mkdir /go: permission denied
 undefined  
gopkgs: failed to install gopkgs(github.com/uudashr/gopkgs/v2/cmd/gopkgs): Error: Command failed: /usr/local/go/bin/go get -v github.com/uudashr/gopkgs/v2/cmd/gopkgs
go: downloading github.com/uudashr/gopkgs v1.3.2
go: writing stat cache: mkdir /go: permission denied
go: downloading github.com/uudashr/gopkgs/v2 v2.1.2
go get github.com/uudashr/gopkgs/v2/cmd/gopkgs: mkdir /go: permission denied
 undefined  
go-outline: failed to install go-outline(github.com/ramya-rao-a/go-outline): Error: Command failed: /usr/local/go/bin/go get -v github.com/ramya-rao-a/go-outline
go: downloading github.com/ramya-rao-a/go-outline v0.0.0-20200117021646-2a048b4510eb
go get github.com/ramya-rao-a/go-outline: mkdir /go: permission denied
 undefined  
go-symbols: failed to install go-symbols(github.com/acroca/go-symbols): Error: Command failed: /usr/local/go/bin/go get -v github.com/acroca/go-symbols
go: writing stat cache: mkdir /go: permission denied
go: downloading github.com/acroca/go-symbols v0.1.1
go get github.com/acroca/go-symbols: mkdir /go: permission denied
 undefined  
guru: failed to install guru(golang.org/x/tools/cmd/guru): Error: Command failed: /usr/local/go/bin/go get -v golang.org/x/tools/cmd/guru
go: downloading golang.org/x/tools v0.0.0-20200930213115-e57f6d466a48
go get golang.org/x/tools/cmd/guru: mkdir /go: permission denied
 undefined  
gorename: failed to install gorename(golang.org/x/tools/cmd/gorename): Error: Command failed: /usr/local/go/bin/go get -v golang.org/x/tools/cmd/gorename
go: downloading golang.org/x/tools v0.0.0-20200930213115-e57f6d466a48
go get golang.org/x/tools/cmd/gorename: mkdir /go: permission denied
 undefined  
gotests: failed to install gotests(github.com/cweill/gotests/...): Error: Command failed: /usr/local/go/bin/go get -v github.com/cweill/gotests/...
go: writing stat cache: mkdir /go: permission denied
go: downloading github.com/cweill/gotests v1.5.3
go get github.com/cweill/gotests/...: mkdir /go: permission denied
 undefined  
gomodifytags: failed to install gomodifytags(github.com/fatih/gomodifytags): Error: Command failed: /usr/local/go/bin/go get -v github.com/fatih/gomodifytags
go: writing stat cache: mkdir /go: permission denied
go: downloading github.com/fatih/gomodifytags v1.6.0
go get github.com/fatih/gomodifytags: mkdir /go: permission denied
 undefined  
impl: failed to install impl(github.com/josharian/impl): Error: Command failed: /usr/local/go/bin/go get -v github.com/josharian/impl
go: writing stat cache: mkdir /go: permission denied
go: downloading github.com/josharian/impl v1.0.0
go get github.com/josharian/impl: mkdir /go: permission denied
 undefined  
fillstruct: failed to install fillstruct(github.com/davidrjenni/reftools/cmd/fillstruct): Error: Command failed: /usr/local/go/bin/go get -v github.com/davidrjenni/reftools/cmd/fillstruct
go: downloading github.com/davidrjenni/reftools v0.0.0-20191222082827-65925cf01315
go get github.com/davidrjenni/reftools/cmd/fillstruct: mkdir /go: permission denied
 undefined  
goplay: failed to install goplay(github.com/haya14busa/goplay/cmd/goplay): Error: Command failed: /usr/local/go/bin/go get -v github.com/haya14busa/goplay/cmd/goplay
go: writing stat cache: mkdir /go: permission denied
go: downloading github.com/haya14busa/goplay v1.0.0
go get github.com/haya14busa/goplay/cmd/goplay: mkdir /go: permission denied
 undefined  
godoctor: failed to install godoctor(github.com/godoctor/godoctor): Error: Command failed: /usr/local/go/bin/go get -v github.com/godoctor/godoctor
go: downloading github.com/godoctor/godoctor v0.0.0-20200702010311-8433dcb3dc61
go get github.com/godoctor/godoctor: mkdir /go: permission denied
 undefined  
dlv: failed to install dlv(github.com/go-delve/delve/cmd/dlv): Error: Command failed: /usr/local/go/bin/go get -v github.com/go-delve/delve/cmd/dlv
go: writing stat cache: mkdir /go: permission denied
go: downloading github.com/go-delve/delve v1.5.0
go get github.com/go-delve/delve/cmd/dlv: mkdir /go: permission denied
 undefined  
gocode-gomod: failed to install gocode-gomod(github.com/stamblerre/gocode): Error: Command failed: /usr/local/go/bin/go get -v -d github.com/stamblerre/gocode
go: writing stat cache: mkdir /go: permission denied
go: downloading github.com/stamblerre/gocode v1.0.0
go get github.com/stamblerre/gocode: mkdir /go: permission denied
 undefined  
godef: failed to install godef(github.com/rogpeppe/godef): Error: Command failed: /usr/local/go/bin/go get -v github.com/rogpeppe/godef
go: writing stat cache: mkdir /go: permission denied
go: downloading github.com/rogpeppe/godef v1.1.2
go get github.com/rogpeppe/godef: mkdir /go: permission denied
 undefined  
goformat: failed to install goformat(winterdrache.de/goformat/goformat): Error: Command failed: /usr/local/go/bin/go get -v winterdrache.de/goformat/goformat
go: downloading winterdrache.de/goformat v0.0.0-20180512004123-256ef38c4271
go get winterdrache.de/goformat/goformat: mkdir /go: permission denied
 undefined  
golint: failed to install golint(golang.org/x/lint/golint): Error: Command failed: /usr/local/go/bin/go get -v golang.org/x/lint/golint
go: downloading golang.org/x/lint v0.0.0-20200302205851-738671d3881b
go get golang.org/x/lint/golint: mkdir /go: permission denied
 undefined 

My main OS is Windows 10 and I use VS Code 1.49.2 in combination with WSL2 and Ubuntu 20.04. The Go version is go1.15.2 linux/amd64. What permission do I need to change?

1

There are 1 answers

0
Laima On

I've just upgraded to WSL2 (using Ubuntu 20.04 on Windows 10) and found your question because I was tearing my hair out trying to figure out why I couldn't run a simple sam build without getting permissions error. I discovered that it was part of the permissions configured in /etc/wsl.conf.

Based on a vscode issue I saw, I set the wsl.conf file to the following settings:

[automount]
enabled=true
root = /
options="metadata,uid=1000,gid=1000,umask=002,dmask=002,fmask=002"

The options set the owner of the files as user with uid=1000 and group with gid=1000 instead of root. That should be the admin user you're logging in as, so you won't have to overcome root ownership of all the files. The umask, dmask and fmask sets the mask for file permissions on newly created files and basic gives read/write permissions on new files and directories, so you'll be able to install files again.

I'm not sure if this is the issue you're running into, but it looks very similar, and I had a very difficult weekend trying to figure it out, so I'd like to pass it along!