This is a creation in Article, where the information may have evolved or changed.
1. Download and install
Download the latest version of the Golang installation package from https://golang.org/dl/, respectively, with windows\linux\apple osx\ source package.
Golang's official website is https://golang.org/, the corresponding Chinese version of the website is https://go-zh.org/, for the Chinese developers are still very friendly ah.
2. Environment configuration
Go language compared to other languages, the initial installation configuration to be a bit cumbersome, you need to manually configure the environment variable goroot, the value of the installation path to go, in Windows installation as an example, I here for c:/go, and then add%goroot%\bin in the path path (if it is a Linux system, repair Change the/etc/profile, and then through the Source/etc/profile hot load can be). Once the goroot and PATH environment variables have been configured, the GO command can be executed successfully on the command line.
In addition, when you set up go engineering, you also need to configure the GOPATH environment variable (which is a bit annoying), which indicates the directory where the Go project resides.
3. Compiling project
Below to compile the go project, for example, our project directory is as follows, where SRC represents the code folder, Src\main\server.go is the file where the main function is located:
Configure the GOPATH environment variable:
Next we can use the command line to compile the project, you can use go install main, the Bin folder in the project directory to generate the Main.exe, and under the Pkg folder to generate intermediate files. If you use go build main to build, the Main.exe is generated to the command line current directory, and the intermediate files are not saved. (When using go build, you can also directly specify the file name to be compiled instead of the package name, if you can use go build D:\src\MonsterBook\Trunk\server\src\main\server.go here), we can also go directly The Run command compiles directly, such as Go run D:\src\MonsterBook\Trunk\server\src\main\server.go
4. Summary
As you can see, the Go language configuration is a bit cumbersome, after downloading the installation, to configure Goroot\path\gopath three environment variables, and when you create a go project, it is generally necessary to modify the Gopath variable. The go language provides a powerful set of command-line tools, and here is a simple introduction to the compile-related go build\go install\go Run command.