Error GOLang: no install location for directory


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:

yusuf@yusuf-he:~/go-learn2/src/github.com/yoesoff/hello$

here is the official documentation regarding golang Workspace Directory Structure

A workspace is a directory hierarchy with three directories at its root:

  • src contains Go source files,
  • pkg contains package objects, and
  • bin contains executable commands.

The go tool builds source packages and installs the resulting binaries to the pkg and bin directories.

The src subdirectory 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:

golangworkspacetree

here is the official documentation regarding $GOPATH

The GOPATH environment variable

The GOPATH environment 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 GOPATH accordingly. Your workspace can be located wherever you like, but we’ll use $HOME/work in this document. Note that this must not be the same path as your Go installation. (Another common setup is to set GOPATH=$HOME.)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s