Goroot is the Go installation path
Add the following statement in the ~/.bash_profile:
Goroot=/usr/local/go
Export Goroot
Of course, to execute the GO command and Go tool, you need to configure the path of the go executable file:
The operation is as follows:
The configuration in ~/.bash_profile is as follows:
Export Path:path:goroot/bin
If Windows needs to be used; the symbol splits two paths, Mac and Unix-like are separated by: symbol Gopath:
Go install/go get and go tools are used to gopath environment variables.
Gopath is the search path as the compiled binary storage destination and import package (in fact your working directory, you can create your own go source file under SRC and then start working).
Gopath consists of three main directories: bin, pkg, SRC
The bin directory mainly contains executable files; Pkg directory to store compiled library files, mainly *.a > pieces; The source files of go are mainly stored in the SRC directory.
Do not set the Gopath to the Go installation path,
You can create a directory yourself under the user directory, such as Gopath
The operation is as follows:
CD ~
mkdir Gopath
Add the following statement in the ~/.bash_profile:
Gopath=/users/username/gopath
Gopath can be a directory listing, go get download third-party library, will generally be downloaded to the first directory of the list
You need to configure the executable directory in the Gopath to the environment variable, otherwise the third-party go tool that you download yourself cannot be used, as follows:
Configured in ~/bash_profile,
Export $PATH: $GOPATH/bin
Create a Go project and compile and run:
mkdir Goproject
CD Goproject
Touch Hello.go
In the Hello.go, enter:
Package Main
Import "FMT"
Func Main () {
Fmt. Println ("Hello, GO!")
}
Execute the Go build command under the project root to build your project, and the build will generate a hello file
Run the generated file./hello, terminal output: Hello, GO!
Of course you can also run the command go running hello.go directly to execute the program.
If you want the above settings to take effect, you can execute the command: source ~/.bash_profile, all of the above actions are operating under the Mac system, and if it is a non-MAC system, make your own work.