英文:
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 examplesudo 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论