English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
You can download from the official websitehttps://golang.google.cn/dl/ Download the corresponding version according to the system environment, unzip it after downloading in the Linux environment, and follow the installation guide in the Windows environment to install step by step
Add go to the Path environment variable (unzip the go installation package to)/usr/(in the local directory)
vim /etc/profile Add:/usr/local/go/bin Add to the PATH global variable and save Then execute source /etc/profile # /etc/profile # System startup execution file # This file will be executed when the operating system starts. Execution will add/user/local/Add go to the global variable
GOROOT setting: Go installation path
vim /etc/profile Add new: export GOROOT = "/usr/local/go"
GOPATH setting: go working environment, generally there will be three directories under this path: bin, pkg, src, you can place multiple project source codes in src, and compile the files in bin
Create a new Go working environment directory goworks, and create the subdirectories src, pkg, and bin under this directory
vim /etc/profile Add new: export GOROOT = "/goworks" Then execute source /etc/profile
Under Windows, after the go installation package is installed successfully, it will automatically add go to the path directory, so there is no need to add go to the Path environment variable
GOROOT setting: Go installation path
"My Computer"=> "Properties"=> "Advanced System Settings"=> "Environment Variables"=> "System Environment Variables", add a new environment variable GOROOT, as shown below
GOPATH setting:
Delete the GOPATH setting in the user variables, which is the working directory added by default when go is installed, and it is generally not used
Create a new Go working environment directory goworks, and create the subdirectories src, pkg, and bin under this directory
Add a new environment variable GOPATH pointing to the Go working environment directory GoWorks, as shown below
In goworks/Create a directory helloworld under the src directory, and create a file named main.go with the following code:
package main import "fmt"func main(){ fmt.Println("Hello World!") }
Under Windows, open cmd, cd to goworks/src/Under the helloworld directory, run: go run main.go, and the running result is as follows:
The go environment installation is completed
Of course, development cannot do without IDE tools, and VSCode and Sublime are recommended