Install the GO language
The GO language supports multi-platform operating systems
Go’s website is golang.org
The domestic address is: golang.google.cn
Download the installation package and proceed with the installation
1. The UNIX/Linux installation
Here is how to install using binary installation files
#Decompress the installation packageThe tar - ZXVF go1.16.5. Linux - arm64. Tar. Gz
#Move the installation package to the system directory
sudo mv go /usr/local
Copy the code
Set the environment variables, open the system profile file using sudo vim /etc/profile, and add the following at the end of the file
#This is where go is installed, and the IDE will read the contents of GO_ROOT later
export GOROOT=/usr/local/go
#Set up the domestic packet acceleration mirror of GO
export GOPROXY=https://goproxy.cn
#Add the binary executable of Go to the PATH environment variable and call it from the terminal
export PATH=$GOROOT/bin:$PATH
Copy the code
Finally, run the source /etc/profile command to reload the profile file
Golang also relies on other environment variables. You can use the go nev command to view all of golang’s dependent environment variables, which we will cover one by one when needed later
2. MAC and Windows installation
For Windows, double-click a file with the **. Msi suffix to install it. For MAC, double-click a file with the. PKG ** suffix to install it. Finally, set GOROOT, GOPROXY and PATH environment variables correctly.
3. Verify the installation
Finally, run the Go version command on the CLI. If the go version is as follows, the installation is successful
Go version go1.16.4 Darwin/amd64Copy the code
Configure the development environment
1. Install the IDE
To make it easy to write the GO program, we need to install the IDE. Let’s take VS Code as an example to configure the go development environment.
VS Code’s official website is code.visualstudio.com/
Download the operating system corresponding to our computer, double click to install as prompted.
Finally, we opened vs Code’s plug-in store to install the official Go language extension pack, as shown below
2. Write your first program
In any working directory, create a test.go file and add the following
package main
import "fmt"
func main(a){
fmt.Println("Hello World")}Copy the code
Run the go command on the CLI. The following output is displayed
pan@pandeMBP learn % go run test.go
Hello World
pan@pandeMBP learn %
Copy the code