This is a creation in Article, where the information may have evolved or changed.
Preface: This article mainly introduces the installation of Golang and the use of Golang editor, and our first classic case: Hello world.
First, why is Golang
Golang, also known as Go, is an open-source, compiled, static type of programming language developed by Google. It has the following characteristics:
- Go native supports concurrency (Concurrency), making it ideal for writing multithreaded programs.
- Golang is a compiled language. The source code is compiled into an executable binary file.
- Go is a static type of language, and its type system has no hierarchy. So users don't need to spend time on defining relationships between types, which makes them more lightweight than typical object-oriented languages.
Ii. selection of Golang development kits
We can choose the appropriate development kit according to our machine operating system, such as your Windows 64-bit, choose WINDOWS-AMD64 Toolkit, and Linux 32-bit Select Linux-386 Toolkit. You can check your own operating system, and then choose, Mac is now 64-bit, direct selection on it.
The development kit is also available in the installation and compression versions. Installation version, as the name implies, double-click to open the Installation Wizard will appear, let you choose the installation of the path to help you set up the environment variables and other information, more convenient. The installation version is unique to Mac and Windows, and their names are similar to the following:
Compressed version is a compressed file, you can extract the content inside. Compressed version We need to unzip after downloading, and then move to the path to be stored, and configure the environment variables and other information, compared to the installation version, more complex, more manual configuration. Their names are similar to the following:
Depending on your operating system, select Download Development Kit, the official download address for the Go language is https://golang.org/dl/.
Third, the installation Golang under the Mac
Mac is divided into compressed version and installation version, they are all 64-bit. The compact version and Linux are much the same, because both Mac and Linux are UNIX-based, the end of this piece is basically the same. The following is an example of a compressed version of Mac
After downloading, start extracting this file:
sudo tar -C /usr/local/ -xf go1.9.2.darwin-amd64.tar.gzcd /usr/local
To add a Global environment variable:
export GOROOT=/usr/local/goexport PATH=$PATH:$GOROOT/bin
Where the GOROOT environment variable represents our go install directory, so that other software such as our use of the go Development IDE can automatically find our go installation directory, to automatically configure the Go SDK.
Path is to add the/usr/local/go/bin directory to the environment variable, so that I can enter the terminal directly into the go and other common commands used, and not absolute path, after all, the absolute path to lose once too much trouble
The source Global environment variable makes it effective:
source /etc/profile
You can see the following effect after it takes effect:
localhost:bin rentom$ go versiongo version go1.9.2 darwin/amd64
There is almost no difference between the installation under Linux and the Mac, but the production environment suggests creating a soft connection that facilitates later maintenance.
Iv. introduction of Golang IDE Goland
Official website: https://www.jetbrains.com/, after downloading the installation, start setting the basic environment variables for GO
Note: If you have more than one version of Go you can choose the version from the right-hand menu, very convenient
The Gopath Settings feature in Gogland is very practical and powerful, you can configure multiple global Gopath (the IDE automatically recognizes Gopath in environment variables, not tick), can configure multiple project-level gopath, and can even configure multiple module-level Gopath.
V. Create a new Go project
Here you will need to select the Goroot you have configured above, and the new project will automatically associate the global Gopath. Write a Hello world program below.
VI. Import a new Go Project
If you already have the Go Project code locally, simply select File-open from the main menu and open your project directory. The latest version of Goland has a very thoughtful little feature that automatically matches your current set of global goroot. Of course, you can also change it in the settings.
End
In order to facilitate communication, I opened the public number (attention to see more wonderful) and QQ Group, QQ Group 1 (291519319) and QQ Group 2 (659336691). Like the technology to communicate with it