In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to install Go language environment". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "how to install Go language environment" together.
Download Go
Version Selection: Choose the version that suits your computer
Installation: Windows installation
Select your version and double-click to install
Configure GOPATH
GOPATH environment variable, to indicate the storage path of your go project (development directory)
GOPATH path is best to set only one, all project code is placed in GOPATH src directory.
Go After version 1.11, you can choose to turn on go mod mode without configuring GOPATH.
We installed version 1.16 here, that is, you can not configure GOPATH, but still understand the GOPATH configuration, because 1.16 go mod is not enabled by default
Environment configuration.png image.png
You have to manually create these three directories
image.png
Go's Project Structure
When developing Go, our code is always stored in the $GOPATH/src directory. After the project passes through the go build,go install or go get instructions, the downloaded third-party package source code files will be placed in the $GOPATH/src directory, the resulting binary executable files will be placed in the $GOPATH/bin directory, and the generated intermediate cache files will be saved in the $GOPATH/pkg directory.
If we use version control tools (svn and git) to manage our project code, we can simply add source code to the $GOPATH/src directory. The contents of the bin and pkg directories do not require version control.
The first go program
Go uses UTF-8 encoded text files to store source code. Like other languages, text editors can develop Go. I use GOland, but this software is paid. The open source editor vscode wants to write Go better than free ones. (vscode default English can install Chinese plug-ins)
Create a project hello in src directory of GOPATH we just created Create a main.go
package main //Announcements main package, indicating that the program is executable import "fmt" //import built-in fmt package func main(){ // main function, is the entry fmt.Println("Hello World! ") //Right-clicking an execute button will output Hello World! on the terminal. }
The first go program will be experienced.
Compile the go project independently of the compiler
go build
In the hello directory just created, execute go build my windows environment will generate a hello.exe file, that is, hello.exe can be executed in the terminal will also be output in the terminal
Hello World!
go install
Go install means install. It compiles the source code to get an executable file, and then moves the executable file to the bin directory of GOPATH. Since our environment variable is configured with the bin directory under GOPATH, we can execute executable files directly from anywhere.
Thank you for reading, the above is the content of "how to install the Go language environment", after learning this article, I believe that everyone has a deeper understanding of how to install the Go language environment, and the specific use situation needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.