“Permission denied” error during initialization [c

2019-09-21 18:36发布

As I am new to Go, I am trying to execute my first Go code with terminal, as the code compiles and gives an output, But I am getting an error of initialization failure

go: disabling cache (/home/myname/.cache/go-build) due to initialization 
failure: open /home/myname/.cache/go-build/log.txt: permission denied

How can I solve this?

标签: linux go
1条回答
别忘想泡老子
2楼-- · 2019-09-21 19:12

The error you are facing is that you don't have enough privileges to create/delete/modify inside the directory you are trying to work in.

How to solve it?

  • The easy way: You can solve this problem by changing the permissions of the directory you are working on by using the chmod command, for example: sudo chmod -R 777 /testDir. Using this you are allowing the owner - group - others to create, delete, and modify the directory + the sub directories (when -R is used). So i suggest you do sudo chmod -R 754 /testDir for now.

  • The less easy way: You can use chown which means changing the ownership for the directory for both the owner and the group, for example sudo chown -R newOwner:newGroup /testDir and by that you have the ultimate ownership for the directory + the sub directories.

  • The most easy yet a dangerous way: You can work in the directories as a root and do what ever you like, when you open up the terminal use the command sudo -s and enter your password to be a root user. Not Recommended because it can destroy system files if you used it wrong! see the risks here Why is it bad to log in as root?

查看更多
登录 后发表回答