I think the problem is your environment variable GOPATH
, GOROOT
seems to be right.
You should point the variable to the directory you want your workspace to be.
Here, for example, it is configured like this:
$ go env
GOARCH="386"
GOBIN=""
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/admin/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_386"
GCCGO="gccgo"
GO386=""
CC="gcc"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build890319421=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
The environment variable GOROOT
points to the installation files:
$ ls -la $GOROOT
total 168
drwxr-xr-x 11 root root 4096 May 24 18:16 .
drwxrwsr-x 11 root staff 4096 May 30 10:48 ..
drwxr-xr-x 2 root root 4096 May 24 18:15 api
-rw-r--r-- 1 root root 33243 May 24 18:15 AUTHORS
drwxr-xr-x 2 root root 4096 Aug 8 09:36 bin
drwxr-xr-x 4 root root 4096 May 24 18:16 blog
-rw-r--r-- 1 root root 1366 May 24 18:15 CONTRIBUTING.md
-rw-r--r-- 1 root root 45710 May 24 18:15 CONTRIBUTORS
drwxr-xr-x 8 root root 4096 May 24 18:15 doc
-rw-r--r-- 1 root root 5686 May 24 18:15 favicon.ico
drwxr-xr-x 3 root root 4096 May 24 18:15 lib
-rw-r--r-- 1 root root 1479 May 24 18:15 LICENSE
drwxr-xr-x 14 root root 4096 May 24 18:16 misc
-rw-r--r-- 1 root root 1303 May 24 18:15 PATENTS
drwxr-xr-x 6 root root 4096 May 24 18:16 pkg
-rw-r--r-- 1 root root 1399 May 24 18:15 README.md
-rw-r--r-- 1 root root 26 May 24 18:15 robots.txt
drwxr-xr-x 46 root root 4096 May 24 18:15 src
drwxr-xr-x 17 root root 12288 May 24 18:15 test
-rw-r--r-- 1 root root 7 May 24 18:15 VERSION
And the environment variable GOPATH
points to where my workspace is:
$ ls -la $GOPATH
total 20
drwxr-xr-x 5 admin admin 4096 Aug 7 20:10 .
drwxr-xr-x 7 admin admin 4096 Sep 15 07:00 ..
drwxr-xr-x 2 admin admin 4096 Aug 16 02:11 bin
drwxr-xr-x 3 admin admin 4096 Aug 7 20:10 pkg
drwxr-xr-x 8 admin admin 4096 Aug 7 21:55 src
Just create the src
folder and put your source code in there, the rest of the folders are usually created as you compile code with go build
.