Ubuntu 13.10,Golang构建和运行时,终端显示错误bash: ./filename: 权限被拒绝。

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

Ubuntu 13.10 , Golang build and run, the terminal display error bash: ./filename : Permission denied

问题

我正在尝试在使用命令go build后运行Go的可执行文件,而不是输入go run filename.go

我在存放Golang源文件的目录中输入了go build。在可执行文件创建完成后,我输入./filename来运行它。然后终端显示了一行:

bash: ./filename: 权限被拒绝

我尝试通过输入以下命令来更改文件名的权限:

chmod u+x filename

但是这个操作没有产生任何效果。每当我输入./filename时,仍然会出现权限被拒绝的错误。

是否有其他方法可以从源代码构建Golang应用程序,然后从可执行文件中运行它?

如果我在Windows命令提示符中执行此任务,一切都很顺利。在输入go build后,filename.exe被创建,并且当我输入./filename.exe时没有任何问题。

英文:

I am trying to run Go's executable file after using command go build instead of typing go run filename.go.

I typed go build in the directory where the Golang source file resides. After the executable file had been created, I typed ./filename to run it. Then the terminal displayed a line :

bash : ./filename : Permission denied 

I had tried to change the permission of the filename by typing :

chmod u+x filename 

But this action doesn't give any effects. The permission denied error still occurs whenever I type ./filename.

Is there another way to build a Golang applications from source code, and then run it from executable file?

All things done well if I do this task in Windows command prompt, after typing go build, the filename.exe is created and there is no any problem when I run it by typing ./filename.exe.

答案1

得分: 3

NTFS和FAT与Unix具有不同的权限模型。这意味着在这样的文件系统上没有可执行标志。调用chmod a+x FILE是无效的。Linux通过为每个文件设置掩码来模拟经典的Unix权限,以解决NTFS文件系统上的这些问题。

要解决这些问题,可以将可执行文件移动到不同的文件系统,或者更改挂载标志以使用启用可执行标志的权限掩码(适用于所有文件)。

英文:

NTFS and FAT have different permission models than Unix. This especially means that there is no executable flag on such a file system. Calling chmod a+x FILE is a no-op. Linux emulates classical Unix permissions on NTFS file systems by setting a mask for each file that contains the would-be permissions.

To fix these problemss, either move executables to a different file system or change the mount flags to use a permission mask that enables the executable-flag (for all files).

huangapple
  • 本文由 发表于 2014年2月6日 19:35:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/21601818.html
匿名

发表评论

匿名网友

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

确定