Ubuntu WSL2 Golang安装工具:权限被拒绝

Ubuntu WSL2 Golang安装工具:权限被拒绝,ubuntu,go,permissions,wsl-2,Ubuntu,Go,Permissions,Wsl 2,我试图在WSL2/Ubuntu中安装golang工具,以便将它们与VSCode一起使用。每次我想通过VSCode安装它们时,都会收到“权限被拒绝”消息: Tools environment: GOPATH=/go Installing 17 tools at /go/bin in module mode. gocode gopkgs go-outline go-symbols guru gorename gotests gomodifytags impl

我试图在WSL2/Ubuntu中安装golang工具,以便将它们与VSCode一起使用。每次我想通过VSCode安装它们时,都会收到“权限被拒绝”消息:

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 

我的主要操作系统是Windows10,我将VS代码1.49.2与WSL2和Ubuntu 20.04结合使用。Go版本是go1.15.2Linux/amd64。我需要更改什么权限?

我刚刚升级到WSL2(在Windows 10上使用Ubuntu 20.04)并发现了您的问题,因为我正在绞尽脑汁试图弄清楚为什么我无法运行简单的sam构建而不获得权限错误。 我发现它是/etc/wsl.conf中配置的权限的一部分

根据我看到的vscode问题,我将wsl.conf文件设置为以下设置:

[automount]
enabled=true
root = /
options="metadata,uid=1000,gid=1000,umask=002,dmask=002,fmask=002"
这些选项将文件的所有者设置为uid=1000的用户和gid=1000而不是root的组。这应该是您作为管理员用户登录的,因此您不必克服所有文件的root所有权。 umask、dmask和fmask为新创建的文件设置文件权限掩码,basic为新文件和目录提供读/写权限,因此您可以再次安装文件


我不确定这是否是你遇到的问题,但它看起来非常相似,我周末很难找到答案,所以我想把它传下去

可能不使用
/go
。使用
~/go
或其他您有权访问的目录。以管理员身份运行WSL,然后重试