登录
首页 >  Golang >  Go问答

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

来源:stackoverflow

时间:2024-04-16 11:33:33 251浏览 收藏

欢迎各位小伙伴来到golang学习网,相聚于此都是缘哈哈哈!今天我给大家带来《WSL2 Golang 安装工具:权限被拒绝》,这篇文章主要讲到等等知识,如果你对Golang相关的知识非常感兴趣或者正在自学,都可以关注我,我会持续更新相关文章!当然,有什么建议也欢迎在评论留言提出!一起学习!

问题内容

我正在尝试在 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

我的主要操作系统是 windows 10,我将 vs code 1.49.2 与 wsl2 和 ubuntu 20.04 结合使用。 go版本是go1.15.2 linux/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 提供新文件和目录的读/写权限,以便您能够再次安装文件。

我不确定这是否是您遇到的问题,但看起来非常相似,而且我度过了一个非常困难的周末试图解决这个问题,所以我想把它传递出去! p>

今天关于《WSL2 Golang 安装工具:权限被拒绝》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>