1, go download source package from the official website
wget https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
2, in the / usr / local decompression Source Package
sudo tar -zxf go1.12.5.linux-amd64.tar.gz -C /usr/local
3, add / usr / local / go / bin directory to the PATH environment variable
export PATH=$PATH:/usr/local/go/bin
4, the test environment
Enter the go version can see the version number says that the installation was successful
5, to establish a working space
New go in the directory / home directory (file names at will), and then were three new directories under the directory go:
src ---- Inside each subdirectory is a package. Go inside the package is a source code file
generated after pkg ---- compiled package object file
bin ---- generated executable file.
6, GOPATH set environment variables
vi / etc / profile
and add the following line:
Export GOPATH = / Home / Go
After saving, execute the following command, the environment variable to take effect immediately:
Source / etc / Profile
At this point go environment have all been installed, we go to write the first program
7, create a file in the src folder for hello, create a new file folder in the file hello.go
It reads as follows:
package main
import "fmt"
func main(){
fmt.Printf("hello world!\n")
}
Compiled file folder in the file hello:
go install
Will see an executable file in the bin directory, enter
./hello
You can see
hello world!
Output