我使用go version go1.5.1 linux/amd64的debian 8.2 3.16.0-4-amd64。我golang使用https://golang.org/doc/install安装。
这是我放在我的~/.profile文件中的内容
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:/home/shivams/go/bin
Run Code Online (Sandbox Code Playgroud)
go env在我的机器上运行给出了这个输出
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/shivams/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
Run Code Online (Sandbox Code Playgroud)
里面的目录结构/home/shivams/go是{pkg,src,bin}. 在 src 目录中,它就像test/hello.go.
如果我在srcdir 中并运行go run test/hello.go它,它将完美运行。此外,如果我运行go build test/hello.go它会hello在同一目录中创建一个可执行文件。
但是,如果我尝试运行,go install test/hello.go则会出现此错误
go install: no install location for .go files listed …