1, Go language environment installation
1.1 Obtaining development packages
The Go language supports the following systems:
-
Windows
-
Linux
-
Mac: also known as Darwin
-
FreeBSD
The development package can be downloaded from golang.org/dl
If you can’t open it, use this address: golang.google.cn/dl
Depending on your system, download the appropriate development kit.
In Windows, for example, download the Windows installer go1.16. Windows – amd64. Msi, download address: golang. Google. Cn/doc/install…
1.2 Development Package Installation
(1) Install the development package.
Double-click the downloaded installation package go1.16.Windows-amd64.msi to install it step by step.
By default, it will be installed in the C: Program Files\Go directory. (Different versions may vary, subject to actual conditions!)
(2) Configure the Go environment variable.
By default, Go environment variables are automatically configured after the installation of the development package. If they are not configured or do not meet your requirements (GOPATH can be configured based on your actual situation), install the following configuration methods to configure or adjust the environment variables.
According to the principle that The Windows system is looking for executable programs, the path where Go is can be defined in environment variables, so that the system can help us find the program to run and execute, so that any directory can execute Go instruction. The configured environment variables are as follows:
Path Adds the /bin directory of the Go development package, for example, C: Program Files\Go\bin
GOPATH Work directory, set the Go project work path, can be set according to their own preferences.
Right-click “My Computer” -> Properties -> Advanced System Settings -> Advanced -> System Variables:
Add the following environment variables:
- Path: ` C: \ Program Files \ Go \ bin `
- GOPATH:
E:\github\golangLearning
, a customized directory is used as the Go project directory.
(3) Environmental inspection.
Open the CMD command line interface (CLI) and run the go version command to check whether the installation succeeds and takes effect.
2. IDE installation
2.1 IDE
Common Go development ides are as follows:
- Visual Studio Code (Visual Studio Code)
Microsoft’s product, a tool that runs on Mac OS, Windows, and Linux, provides syntax highlighting for the Go language by default. Install Go language plug-in, can also support intelligent tips, compile and run functions.
- Sublime Text
You can try it for free, and it also supports Go code syntax highlighting by default, but you need to buy it after you save it a certain number of times.
- Vim
It is a text editor developed from VI (Linux), code completion, compilation and error jump and other convenient programming functions are very rich.
- Emacs
More than just an editor, it is powerful enough to be called an integrated development environment.
- The Eclipse IDE
Open source, free, and available with the GoEclipse plug-in.
- LiteIDE
LiteIDE is a cross-platform lightweight integrated development environment (IDE) specially developed for Go language.
- JetBrains
IDE tools such as GoLand, PhpStrom, WebStrom, and PyCharm all require the Go plug-in.
Go language IDE tools are many, you can choose according to their own preferences, not mandatory requirements.
It is recommended that you use VSCode first. This will give you a better understanding of Go, basic syntax, keywords, etc. Wait until you are familiar with the syntax of Go, then switch to your IDE.)
2.2 installation VSCode
Download: code.visualstudio.com/
Download page you can choose different versions for everyone to download.
I chose the Windows X64 version to download and install directly.
2.3 Go language program runs quickly
(1) VSCode opens the newly created GOPATH project directory.
(2) Create a new file called test.go and write Hello, World! Go program, the code is as follows:
package mainimport "fmt"func main() { fmt.Println("Hello, World!" 1234567)}Copy the code
After saving the file, VSCode will automatically detect any extension packages or plug-ins that may need to be installed, and you will see a pop-up in the lower right corner, as shown below. At this point, we ignore the installation.
(3) Fast operation.
Run the go run test.go command to directly run the test.go program. The result is as follows:
The actual environment is to compile (go build) before running. The go run command takes longer to execute because it involves compilation.)
Here, Go language development environment built!