在Mac上,Go build出现权限被拒绝的错误。

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

Go build is giving permission denied error on mac

问题

我正在尝试运行go build命令,但是遇到了以下错误:go run命令可以正常运行。

open /Users/an../Library/Caches/go-build/32/3284dc1dfe0121246372cec7d0efeba47a547120b3fa696ef6283422d69cd994-a: permission denied

英文:

I am trying to run go build and seeing the following error. go run works fine

open /Users/an../Library/Caches/go-build/32/3284dc1dfe0121246372cec7d0efeba47a547120b3fa696ef6283422d69cd994-a: permission denied

答案1

得分: 1

你遇到的错误可能是由于Go构建缓存目录的权限问题引起的。当你运行go build时,Go会尝试将编译的目标文件写入缓存目录,以便于将来更快地进行构建。然而,似乎Go没有足够的权限写入缓存目录,因此出现了"permission denied"错误。

请确保你有适当的权限写入缓存目录。你可以使用ls命令检查缓存目录的权限和所有权:

ls -ld /Users/an../Library/Caches/go-build

如果你对该目录没有写入权限,你可以将所有权更改为你的用户:

sudo chown -R $(whoami) /Users/an../Library/Caches/go-build
英文:

The error you are encountering is likely due to a permissions issue with the Go build cache directory. When you run go build, Go will try to write the compiled object files to the cache directory for faster future builds. However, it seems that Go doesn't have the necessary permissions to write to the cache directory, hence the "permission denied" error.

Ensure that you have the appropriate permissions to write to the cache directory. You can use the ls command to check the permissions and ownership of the cache directory:

ls -ld /Users/an../Library/Caches/go-build

If you don't have write permissions on this directory, you can change the ownership to your user:

sudo chown -R $(whoami) /Users/an../Library/Caches/go-build

huangapple
  • 本文由 发表于 2023年7月29日 11:51:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76791991.html
匿名

发表评论

匿名网友

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

确定