douduan2272
2017-02-10 22:02
浏览 235
已采纳

为什么不能从/ bin目录中运行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

图片转代码服务由CSDN问答提供 功能建议

我为osx 10.12.2下载了go1.7.5.darwin-amd64.tar.gz。 \ n

解压缩tar并转到/ bin目录以查看Go可执行文件是否将运行。

  $ cd下载/转到/ bin 
 $ ls 
 
总计54560 
-rwxr-xr-x @ 1 bryanwheelock员工9884220 2月10日16:53转到\  n-rwxr-xr-x @ 1 bryanwheelock员工15​​065500 2月10日16:53 godoc 
-rwxr-xr-x @ 1 bryanwheelock员工2976976 2月10日16:53 gofmt 
 
bryanwheelock @ Bryans-MacBook星期五2月10日16:  57:45〜/ Downloads / go / bin 
 $进入版本
-bash:进入:找不到命令
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doujia4619 2017-02-11 03:39
    已采纳

    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/.
      
    点赞 评论
  • douchunsui2395 2017-02-12 20:10
    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.

    点赞 评论

相关推荐 更多相似问题