This is a creation in Article, where the information may have evolved or changed.
Using Google's official Go language installation package under Mac: Https://code.google.com/p/go/downloads/list installed go will automatically add the/usr/local/go/bin directory to the path. This allows us to execute some of the go language commands directly from the console .
http://golang.org/cmd/go/#hdr-gopath_environment_variablehttp://www.cnblogs.com/ghj1976/archive/2013/01/16/2863142.html
go binary compilation package assumes that you are installing go in/usr/local/go (or window is c:\Go) directory. Of course you can also install in other directories, but this time you will need to set Goroot environment variable . http://golang.org/doc/install#install For example, if you install go in your/usr/local/go directory, you should add the following settings to the $home/.profile file.
export GOROOT=/usr/local/goexport GOPATH=$PATH:$GOROOT/bin
Execution: source. Bash_profile (Immediate effect)
Below the window is:
Under Windows, you could set environment variables through the "Environment variables" button on the ' Advanced ' tab The "System" Control panel. Some versions of Windows provide this control panel through the "Advanced system Settings" option inside the "SYSTEM" cont Rol panel.
For example, my Mac, in fact, I did not set goroot, but through the go env can get Goroot directory is:/usr/local/go
I guess this should be the default setting when there is no setting. If there is a setting, it is overwritten.
Gopath
Gopath's role is to tell the GO command and other related tools where to find the go package installed on your system.
Gopath is a list of paths, a typical gopath setting, similar to the path setting, win is separated by semicolons:
GOPATH=/home/user/ext:/home/user/
The path in each list is the location of a workspace. Each workspace has a source file, an object for the related package, and an execution file. Http://golang.org/doc/code.html
Here is a step to create a workspace:
Create the $HOME/mygo directory and the SRC directory as the source code.
$ mkdir -P $HOME /mygo/src # Create a Place to put source code
The next step is to set up Gopath, and you should put the bin directory under this directory in Path environment variable , This allows you to execute directly on the command line without giving the full directory.
export GOPATH= $HOME /mygo export path= $PATH : $HOME /mygo/bin
Gopath must set up the compile and install package, that is, using the standard go directory tree, similar to the following:
Gopath=/home/User/gocode/Home/User/gocode/src/foo/bar/(GO Codeinch PackageBAR) x.go quux/(GO codeinch PackageMain) y.go Bin/quux (installed command) pkg/linux_amd64/ foo/Bar. A (Installed PackageObject
http://golang.org/cmd/go/#hdr-gopath_environment_variable