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: $GOROOT/bin
If Windows needs to be used; symbol split two paths, Mac and Unix-like are used: symbol segmentation
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 bin directory mainly store executable files; Pkg directory to store compiled library files, mainly *.a files; SRC Directory is the main source of Go files do not set the Gopath to 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 list, go get download third-party library, will generally download to the first directory of the list needs to be gopath in the executable directory is also configured in the environment variables, 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.