I just made a mistake related GOPATH on my local environment while learning Golang, here is the error I got:
yusuf@yusuf-he:~/go-learn2/github.com/yoesoff/hello$ go install
go install: no install location for directory /home/yusuf/go-learn2/github.com/yoesoff/hello outside GOPATH
For more details see: go help gopath
and I realized that the mistake was:
here is the official documentation regarding golang Workspace Directory Structure
A workspace is a directory hierarchy with three directories at its root:
srccontains Go source files,
pkgcontains package objects, and
bincontains executable commands.
gotool builds source packages and installs the resulting binaries to the
srcsubdirectory typically contains multiple version control repositories (such as for Git or Mercurial) that track the development of one or more source packages.
To give you an idea of how a workspace looks in practice, here’s an example:
here is the official documentation regarding $GOPATH
GOPATHenvironment variable specifies the location of your workspace. It is likely the only environment variable you’ll need to set when developing Go code.
To get started, create a workspace directory and set
GOPATHaccordingly. Your workspace can be located wherever you like, but we’ll use
$HOME/workin this document. Note that this must not be the same path as your Go installation. (Another common setup is to set