Please correct any bad things you have written
1. Download and install
Golang: 1. golang.google.cn/dl/
Here I download the current version of GO1.13
After the download is complete, double-click install directly, and then install to the C:\Go directory of disk C by default, of course, you can change the directory when installing, but it doesn’t matter, because you can use the Go mod to create projects in any folder. After the installation is complete, win+R shortcut keys open the CMD window and enter
go versionCopy the code
Check the version
And then type in
go env Copy the code
Command to view the environment variable configuration related to go
Notice the GOROOT and GOPATH environment variables here
2. The GOROOT GOPATH
The GOROOT path is where go is installed, or C:\Go if it is installed by default
The GOPATH path is the go workspace path. The default path is in the %USERPROFILE%/go directory, which is the go path in the user directory you are using on your machine, such as mine:
3.VS Code Configure the Go language environment
First of all, if you don’t have VS Code installed and want to use VS Code as the go language development editor, you can download VS code first and install, download VS code at code.visualStudio.com/, after vscode is installed, you can configure the environment.
First of all, vscode can install a Chinese plug-in if you want to use Chinese, if you don’t want to use this step can be omitted
Then install the Go plug-in
After the go plugin is successfully installed, press Ctrl+Shift+P and enter > Go: install. Vscode will automatically search for the command. Select Go: install /Update Tools.
This step may cause some tool installation failures. The previous version of GO1.12 failed, but the 1.13 version did not. If the failure occurs, refer to the following article to solve the problem:
www.liwenzhou.com/posts/Go/00…
If it doesn’t work, you can comment on the specific problems in the comments. After the editor environment is configured for this step, we can start coding.
4. Use go mod to write a Hello World!
1. Find a folder that you create into the directory of the new project, for example now I have created a folder goLearn under my e drive:
Then open the folder with vscode and press CTRL +· to open the console window and initialize the mod in the current directory with go mod init goLearn:
Create a new main.go file and write Hello World! To verify the environment, use the code in the main.go file and run it with the go run main.go command:
package mainimport "fmt"func main() { fmt.Println("Hello World!")}Copy the code
At this point, the Go environment is installed and the first Hello World program written using the Go mod has been successfully written.
Reference article:
www.liwenzhou.com/posts/Go/00…
Juejin. Cn/post / 684490…
zhuanlan.zhihu.com/p/39456054