如果我不在.go文件目录下,则安装失败

I installed Golang via the suggestion https://golang.org/doc/install and it seems I cannot run the go install command like they do on the website

If I run the command from any directory besides the directory that is home to the .go file, then it gives me this error. for example:

go install ./src/tutorial/helloworld/hello.go

or

go install ./path/to/.go/file/hello.go

go install: no install location for .go files listed on command line (GOBIN not set)

but if I run the install from inside the directory that has the .go file everything goes well and it places the final executable in the GOPATH bin folder.

//In the folder that contains my .go file
go install

I have set GOPATH in my .bash_profile and the go installation added the go root directory in /usr/local/go/bin to my PATH

Any ideas why I cannot run install from outside the directory like the instructions on the golang.org website says?

The arguments to the go install command are packages, not .go files. Use these commands to specify the package by relative path.

For the package containing the file ./src/tutorial/helloworld/hello.go:

go install ./src/tutorial/helloworld

For the package containing the file ./path/to/.go/file/hello.go:

go install ./path/to/.go/file