Como um iniciante, encontrei este erro quando estava tentando vários comandos go (construir, executar e instalar). Resumindo, você não pode instalar um filename.go . Você só pode instalar um pacote.
Isso era confuso, porque eu havia aprendido que:
nate:~/work/src/dir $ go run hello/hello.go
hello, world.
funciona bem. Mas não consegui descobrir por que a instalação não funcionava:
nate:~/work/src/dir $ go install hello/hello.go
go install: no install location for .go files listed on command line (GOBIN not set)
nate:~/work/src/dir $ go install hello
can't load package: package hello: cannot find package "hello" in any of:
/opt/go/src/hello (from $GOROOT)
/home/ubuntu/work/src/hello (from $GOPATH)
Não importa em qual diretório eu estava:
nate:~/work/src/dir $ cd hello
nate:~/work/src/dir/hello $ go install hello.go
go install: no install location for .go files listed on command line (GOBIN not set)
nate:~/work/src/dir/hello $ go install hello
can't load package: package hello: cannot find package "hello" in any of:
/opt/go/src/hello (from $GOROOT)
/home/ubuntu/work/src/hello (from $GOPATH)
Essa confusão ocorre porque o go run funciona apenas com arquivos de origem Go (nomes de arquivo que terminam em .go) e o go install aceita apenas pacotes. Os pacotes são nomeados por seus caminhos de importação ou caminho do sistema de arquivos. Portanto:
nate:~/work/src/dir $ go install dir/hello
nate:~/work/src/dir $ go install ./hello/
nate:~/work/src/dir/hello $ go install .
tudo funciona muito bem. O primeiro se refere ao pacote por caminho de importação (dado que $ GOPATH = "/ home / nate / work", as ferramentas go procuram o código-fonte em / home / nate / work / src), os outros são interpretados como sistema de arquivos caminhos por causa dos períodos iniciais.
Veja também os documentos GOPATH .
go installinstala pacotes, não arquivos individuais. Leia todo golang.org/cmd/go e veja como configurar seus arquivos.