I'm trying to install doozer like this
$ goinstall github.com/ha/doozer
I get these errors.
goinstall: os: go/build: package could not be found locally
goinstall: fmt: go/build: package could not be found locally
goinstall: io: go/build: package could not be found locally
goinstall: reflect: go/build: package could not be found locally
goinstall: math: go/build: package could not be found locally
goinstall: rand: go/build: package could not be found locally
goinstall: url: go/build: package could not be found locally
goinstall: net: go/build: package could not be found locally
goinstall: sync: go/build: package could not be found locally
goinstall: runtime: go/build: package could not be found locally
goinstall: strings: go/build: package could not be found locally
goinstall: sort: go/build: package could not be found locally
goinstall: strconv: go/build: package could not be found locally
goinstall: bytes: go/build: package could not be found locally
goinstall: log: go/build: package could not be found locally
goinstall: encoding/binary: go/build: package could not be found locally
转载于:https://stackoverflow.com/questions/7970390/what-should-be-the-values-of-gopath-and-goroot
GOPATH
is discussed in the cmd/go
documentation:
The
GOPATH
environment variable lists places to look for Go code. On Unix, the value is a colon-separated string. On Windows, the value is a semicolon-separated string. On Plan 9, the value is a list.
GOPATH
must be set to get, build and install packages outside the standard Go tree.
GOROOT
is discussed in the installation instructions:
The Go binary distributions assume they will be installed in
/usr/local/go
(orc:\Go
under Windows), but it is possible to install the Go tools to a different location. In this case you must set theGOROOT
environment variable to point to the directory in which it was installed.For example, if you installed Go to your home directory you should add the following commands to
$HOME/.profile
:export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin
Note:
GOROOT
must be set only when installing to a custom location.
(updated version of Chris Bunch's answer.)
GOPATH
is discussed here:
The
GOPATH
Environment Variable
GOPATH
may be set to a colon-separated list of paths inside which Go code, package objects, and executables may be found.Set a
GOPATH
to use goinstall to build and install your own code and external libraries outside of the Go tree (and to avoid writing Makefiles).
And GOROOT
is discussed here:
$GOROOT
The root of the Go tree, often$HOME/go
. This defaults to the parent of the directory whereall.bash
is run. If you choose not to set$GOROOT
, you must run gomake instead of make or gmake when developing Go programs using the conventional makefiles.
I read the go help gopath
docs and was still incredibly confused, but found this little nugget from another go doc page:
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.
As mentioned above:
The GOPATH environment variable specifies the location of your workspace.
For Windows, this worked for me (in Ms-dos window):
set GOPATH=D:\my_folder_for_go_code\
This creates a GOPATH variable that Ms-dos recognizes when used as follows:
cd %GOPATH%
Here is a my simple setup:
directory for go related things: ~/programming/go
directory for go compiler/tools: ~/programming/go/go-1.4
directory for go software : ~/programming/go/packages
GOROOT, GOPATH, PATH are set as following:
export GOROOT=/home/user/programming/go/go-1.4
export GOPATH=/home/user/programming/go/packages
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
So, in short:
GOROOT is for compiler/tools that comes from go installation.
GOPATH is for your own go projects / 3rd party libraries (downloaded with "go get").
If you are using the distro go, you should point to where the include files are, for example:
$ rpm -ql golang | grep include
/usr/lib/golang/include
(This is for Fedora 20)
The GOPATH should not point to the Go installation, but rather to your workspace (see https://golang.org/doc/code.html#GOPATH). Whenever you install some package with go get or go install, it will land within the GOPATH. That is why it warns you, that you most definitely do not want random packages from the internet to be dumped into your official installation.
First run go env
.
If you are see that the go insn't installed you can install it via homebrew or via package and/or other ways.
If you are seeing output then your go is installed.
It shows you all the envs that are set and are not.
If you see empty for GOROOT
:
which go
(On my computer : /usr/local/go/bin/go
)export GOROOT=/usr/local/go
If you see empty for GOPATH
:
~/GO_PROJECTS
export GOPATH=~/GO_PROJECTS
Starting with go 1.8 (Q2 2017), GOPATH will be set for you by default to $HOME/go
See issue 17262 and Rob Pike's comment:
$HOME/go
it will be.
There is no single best answer but this is short and sweet, and it can only be a problem to choose that name if$HOME/go
already exists, which will only happy for experts who already have go installed and will understandGOPATH
.
Regarding GOROOT
specifically, Go 1.9 will set it automatically to its installation path.
Even if you have multiple Go installed, calling the 1.9.x one will set GOROOT
to /path/to/go/1.9
(before, if not set, it assumed a default path like /usr/local/go
or c:\Go
).
See CL Go Review 53370:
The
go tool
will now use the path from which it was invoked to attempt to locate the root of the Go install tree.
This means that if the entire Go installation is moved to a new location, thego tool
should continue to work as usual.This may be overriden by setting
GOROOT
in the environment, which should only be done in unusual circumstances.
Note that this does not affect the result of theruntime.GOROOT()
function, which will continue to report the original installation location; this may be fixed in later releases.
in osx, i installed with brew, here is the setting that works for me
GOPATH="$HOME/my_go_work_space" //make sure you have this folder created
GOROOT="/usr/local/Cellar/go/1.10/libexec"
I had to append
export GOROOT=/usr/local/Cellar/go/1.10.1/libexec
to my ~/.bash_profile on Mac OS X