2013-03-18 37 views
0

從go文檔的外觀看,它們使您看起來像必須在您的$ GOPATH下放置代碼 - 是否正確?Go包/文件位置

我想設立在我的〜/文檔一DIR一個測試項目,但每次我運行go install example/newmath(如在測試例子),它說的following--

λ MacBook-Air src → go install example/newmath 
warning: GOPATH set to GOROOT (/usr/local/go) has no effect 
can't load package: package example/newmath: import "example/newmath": cannot find package 

這是否意味着我需要重置我的$ GOPATH/$ GOROOT?我迷路了。

回答

4

無需在常見情況下設置GOROOT。應該設置(導出)的OTDR,應該設置爲GOPATH

我建議先從

export GOPATH=$HOME 

然後只要把有import "whatever"包成$GOPATH/src/whatever

當您習慣了Go構建系統的工作方式(go {build, install})後,您可以稍後根據自己的需求優化您的GOPATH。在$GOPATH中甚至可以有多個項目,但我真的不認爲這是開始時的擔憂,有時甚至從不擔心。