This is a creation in Article, where the information may have evolved or changed.
Go Environment Building
- Go to the official website, download the MSI file directly and click Install.
- Environment configuration: Mainly including Goroot Gopath GoBin, these three are the Go installation directory, go working directory (custom), and storage of the generated executable directory, the following is my environment variable configuration, for reference only (GoBin directory is also placed in the installation directory bin file , all can, I prefer to put in the working directory inside, feel very convenient):
Environment variables. png
- Open cmd or PowerShell, enter go version and Go env, and see the relevant information is configured successfully. Here you can see the details of your configuration.
View Go info. png
Vscode Environment Configuration
- After configuring the environment already, install Vscode, then install the Go plugin, then restart Vscode.
- The next thing you need is to set Gopath and Goroot in the file-preferences-settings, which is basically done.
Settings. PNG set in JSON.
- However, if you want to run go on Vscode, you will also need to install some framework plugins. Install the version controller git first before installing because these are all to be obtained from GitHub, how to install these plugins, I have a direct point of way, is to create a new Hello.go project on the Vscode, this is you will directly see Vscode will prompt you to install some plug-ins, this is you directly click Install all, it will automatically help you to install the completed. After the installation is complete, you will see your new GitHub folder in your Gopath src directory, which is what you just installed. (because I've already installed it before, so this can't be done)
- Of course you can also enter the following manual installation directly in CMD or PowerShell, the effect is the same.
go get -u -v github.com/nsf/gocode go get -u -v github.com/rogpeppe/godef go get -u -v github.com/golang/lint/golint go get -u -v github.com/lukehoban/go-outline go get -u -v sourcegraph.com/sqs/goreturns go get -u -v golang.org/x/tools/cmd/gorename go get -u -v github.com/tpng/gopkgs go get -u -v github.com/newhook/go-symbols go get -u -v golang.org/x/tools/cmd/guru
- OK, so you can come to your first go program.
package main import "fmt" func main() { fmt.Println("Hello, 世界") }
- Here again, you can install a code runner plugin in Vscode, directly right-click to run, of course, you can also go to the terminal hello.go file directory, run go install or go build, Then locate the Hello.exe file in the bin directory to run. The result is the same.
Image.png
Image.png
by Gai Xiao Classmate