Configure go language environment and compiler recommendation on Windows system

Article Directory

Preface

Before learning go language, you need to configure go language environment on your computer. The environment configuration is similar to java, and it is not too difficult, but configuring the go language compilation environment in VScode is not a simple matter. In addition to VScode, you can also use the Goland compiler. The disadvantage is obvious-it costs money, but you can use it for free for 30 days.


1. Go environment configuration under Windows

First, download the Go installation package: https://studygolang.com/dl

Select the .msi file of the Microsoft Windows version. After the download is complete, install all the way next.

Next, configure the GOPATH system variable. Take the Win10 system as an example, right-click on this computer, select [Properties], then select [Advanced System Settings], and select [Environment Variables]. In the following system variables, select New. Variable name: GOPATH, value: Go installation path G:\Go. Double-click Path in the system variables, and add the path of the bin folder G:\Go\bin at the end.

2. Compiler download and configuration

1.Goland

Download link: https://www.jetbrains.com/go/

After downloading and installing, create a new project and go file and write code. Test code:

package main

import "fmt"

func main() {
	fmt.Printf("Hello, world.\n")
}

2.VScode

If you are used to using vscode, you can also configure the installation environment in vscode for subsequent development. However, the download and installation of third-party dependent packages is time-consuming, because many packages cannot be downloaded directly in vscode and need to be downloaded manually, and even some packages need to be downloaded over the wall.

Search for the plugin Go in vscode and click install. After installation, create a new go file and start coding.

Note: In vscode, you cannot open only one .go file alone. Instead, you need to open the configured GOPATH directory and create a project in this directory. That is to create a folder.

However, vscode will start to prompt that some commands are not available.

Thinking of doing it once and for all, click Install All, but a bunch of prompts that the download failed. Here you need to manually download the missing package, and then put it into the src path of GOPATH. Some bloggers put packages that may be needed into Baidu Cloud for everyone to download. Transfer array . Sometimes, vscode still prompts that certain commands are not available, and you need to manually install these failed packages. I won't repeat it here, just refer to the article in the previous link.

After all the previous packages are downloaded and installed, the program starts to run, and the result shows that the dlv command is not available. This is a tool for compiling go files, we need to download and install it manually.

Select TERMINAL below and enter the  go install github.com/derekparker/delve/cmd/dlv command under GOPATH  . There will be no prompt after the download is successful.

Click [Run] in the menu bar, select [start Debugging], and select Go environment in the pop-up prompt box.

 After running successfully, it will output Hello and world on the console.

 

to sum up

Choose Goland compiler, download and installation is very simple, you can start to enter the world of Go language in minutes, but this software can only be used for free for 30 days; for vscode compiler, the download and installation of the third-party dependency package in the early stage is very troublesome, but after configuration You can always use it.

Guess you like

Origin blog.csdn.net/weixin_39006917/article/details/108273228