即使我已经GOPATH正确设置,我仍然无法通过“go build”或“go run”来找到我自己的包。我究竟做错了什么?
GOPATH
$ echo $GOROOT /usr/local/go $ echo $GOPATH /home/mitchell/go $ cat ~/main.go package main import "foobar" func main() { } $ cat /home/mitchell/go/src/foobar.go package foobar $ go build main.go main.go:3:8: import "foobar": cannot find package
它不起作用,因为您的foobar.go源文件不在名为foobar. go build并go install尝试匹配目录,而不是源文件。
foobar.go
foobar
go build
go install
$GOPATH
export GOPATH="$HOME/go"
$GOPATH/src/foobar/foobar.go
其他推荐步骤:
$GOPATH/bin
$PATH
PATH="$GOPATH/bin:$PATH"
main.go
$GOPATH/src
$GOPATH/src/test
go install test
test