为什么我不能在/bin目录中运行Go二进制文件?

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

Why can't I run the go binary from within the /bin directory?

问题

我下载了适用于OSX 10.12.2的go1.7.5.darwin-amd64.tar.gz文件。

解压缩tar文件后,我进入/bin目录,查看Go可执行文件是否可以运行。

$ cd Downloads/go/bin 
$ ls

总计 54560  
-rwxr-xr-x@ 1 bryanwheelock  staff   9884220 2月 10 16:53 go  
-rwxr-xr-x@ 1 bryanwheelock  staff  15065500 2月 10 16:53 godoc  
-rwxr-xr-x@ 1 bryanwheelock  staff   2976976 2月 10 16:53 gofmt  

bryanwheelock@Bryans-MacBook Fri Feb 10 16:57:45 ~/Downloads/go/bin
$ go version
-bash: go: 命令未找到
英文:

I downloaded go1.7.5.darwin-amd64.tar.gz for osx 10.12.2.

Unpacked the tar and went to the /bin directory to see if the Go executable would run.

$ cd Downloads/go/bin 
$ ls

total 54560  
-rwxr-xr-x@ 1 bryanwheelock  staff   9884220 Feb 10 16:53 go  
-rwxr-xr-x@ 1 bryanwheelock  staff  15065500 Feb 10 16:53 godoc  
-rwxr-xr-x@ 1 bryanwheelock  staff   2976976 Feb 10 16:53 gofmt  

bryanwheelock@Bryans-MacBook Fri Feb 10 16:57:45 ~/Downloads/go/bin
$ go version
-bash: go: command not found

答案1

得分: 3

当您在不提供完整路径的情况下输入命令时,您的系统将尝试在$PATH变量提供的所有文件夹中查找该命令。

在典型的Unix环境中,您的$PATH不包括"当前文件夹"。因此,您需要执行以下操作之一:

  • 使用完整路径调用go(例如$HOME/Downloads/go/bin/go);或者

  • 使用相对路径调用go(例如./go);或者

  • $HOME/Downloads/go/bin添加到您的$PATH变量中;或者

  • .(Unix中表示"当前文件夹")添加到您的$PATH中;或者

  • 将go二进制文件放入已经在您的$PATH中的文件夹中。例如:

      sudo cp $HOME/Downloads/go/bin/* /usr/local/bin/.
    
英文:

When you type a command without giving the full path, your system will try to find it within all the folders provided in $PATH variable.

In typical Unix environment, your $PATH does not include "your current folder". So you need to either:

  • call go by its full path (i.e. $HOME/Downloads/go/bin/go); or

  • call go by its relative path (i.e. ./go); or

  • put $HOME/Downloads/go/bin in your $PATH variable; or

  • put . (Unix way of saying "your current folder") in your $PATH; or

  • put your go binary into folders that already in your $PATH. For example

     sudo cp $HOME/Downloads/go/bin/* /usr/local/bin/.
    

答案2

得分: -1

sudo chmod +x go

看起来它没有执行权限,所以只需更改权限并运行它,然后你应该将go二进制路径设置为环境变量,以便在任何地方都可以访问二进制文件。

英文:
sudo chmod +x go

seems like it does not have execute permission, so just change permission and run it then you should alias your go binary path to your environment to access binary every where.

huangapple
  • 本文由 发表于 2017年2月11日 06:02:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/42169388.html
匿名

发表评论

匿名网友

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

确定