在安装go mockgen时出现了权限被拒绝的错误。

huangapple go评论82阅读模式
英文:

Permission denied when installing go mockgen

问题

我正在尝试在Go语言中安装mockgen包,但是我一直收到"permission denied"的错误,而不知道原因是什么:

go install github.com/golang/mock/mockgen@v1.6.0

输出:

go install github.com/golang/mock/mockgen: copying /tmp/go-build3889221292/b001/exe/a.out: open /home/nocnoc/go/bin/mockgen: permission denied

我尝试使用sudo或以root身份执行,但是我收到以下错误:

sudo: go: command not found

我的GOROOT是/usr/local/go,GOPATH在我的主目录中。GO1111MODULE也已经开启。

我该如何解决这个问题?其他的东西似乎都运行正常,只有mockgen无法安装。

英文:

I am trying to install the mockgen package on go, but I keep receiving a permission denied without knowing why:

go install github.com/golang/mock/mockgen@v1.6.0

Output:

> go install github.com/golang/mock/mockgen: copying /tmp/go-build3889221292/b001/exe/a.out: open /home/nocnoc/go/bin/mockgen: permission denied

I have tried using sudo or executing it as root, but I receive this error

> sudo: go: command not found

My GOROOT is /usr/local/go and GOPATH is in my home directory. GO1111MODULE is also on.

How can I fix it? Everything else seems to run fine, and only mockgen seems to fail to install.

答案1

得分: 2

问题是 ~/go~/go/bin 目录的权限和所有者。通过使用 chown 命令将这两个目录的所有者从 root 更改为我的用户来解决了这个问题:

drwxr-xr-x 10 root   root       4096 Aug 11  2020  go

更改为

drwxrwxr-x 10 nocnoc nocnoc     4096 Aug 11  2020  go

~/go/bin 目录的权限和所有者与上面的目录相同。

英文:

The issue was the permissions and owners of directories ~/go and ~/go/bin. It was solved by using the chown command to change the owner of those two directories from root to my user:

drwxr-xr-x 10 root   root       4096 Aug 11  2020  go

to

drwxrwxr-x 10 nocnoc nocnoc     4096 Aug 11  2020  go

The permissions and owners of ~/go/bin are the same as those for the directory above.

答案2

得分: -1

我不是一个Linux专家,但是尝试运行以下命令:

sudo su
go install github.com/golang/mock/mockgen@v1.6.0
英文:

I'm not a Linux expert, but try running:

sudo su
go install github.com/golang/mock/mockgen@v1.6.0

huangapple
  • 本文由 发表于 2022年4月22日 03:32:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/71959994.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定