Specific steps for installation and configuration of go1.8

Time:2020-3-20

Explain:

I have learned go language (about version 0.9) before, but later it was updated too fast and didn’t use it very much, so it was abandoned. This year, there are projects that need to be developed with go and picked up again.

This is the content that I collated in the process of learning go language. It’s recorded here, which is also convenient for me to consult later.

Operating system: CentOS 6.9 x64

Go language version: 1.8.3

Install go

Binary is directly installed here. Please search for other ways.

1. Download and install go

The command is as follows:


wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz --no-check-certificate
tar zxvf go1.8.3.linux-amd64.tar.gz
mv go /usr/local/

2. Add environment variable

vim /etc/profile

Add the following:


export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go

Make configuration effective:


[[email protected] ~]# source /etc/profile
[[email protected] ~]# go version
go version go1.8.3 linux/amd64
[[email protected] ~]#

Using go

Here is a simple example to introduce the compilation and operation of go language. The deeper content will not be discussed.

File name: test1.go Code:


package main

import "fmt"

func main() {
  fmt.Println("Email : [email protected]")
}

General compilation run

1. Compile go source code into binary file by go build command;

2. Execute the compiled binary file.

An example is as follows:


[[email protected] src]# go build test1.go
[[email protected] src]# ls
test1 test1.go
[[email protected] src]# ./test1
Email : [email protected]
[[email protected] src]#

Run as script

Go language can run programs directly through go run, which can be used to run go programs in script mode.

Method 1:


[[email protected] src]# go run test1.go
Email : [email protected]
[[email protected] src]#

Method 2:

Add the following code to the file header:


//usr/bin/env go run $0 "[email protected]"; exit

Then we can give the executable permission through Chmod.

An example is as follows:


[[email protected] src]# cat test1.go
//usr/bin/env go run $0 "[email protected]"; exit

package main

import "fmt"

func main() {
    fmt.Println("Email : [email protected]")
}

[[email protected] src]# chmod a+x test1.go
[[email protected] src]# ./test1.go
Email : [email protected]
[[email protected] src]#

OK, that’s all. I hope it can help you.

The specific steps of the above go1.8 installation and configuration are all the contents shared by Xiaobian. I hope you can give us a reference and support developepaer.

Recommended Today

Document the third-party framework you use

BackgroundLibrary: generate shape from label implementation “androidx.appcompat:appcompat:$supportVersion” //for androidx implementation ‘com.noober.background:core:1.6.5’ MagicIndicator: indicator repositories { … maven { url “https://jitpack.io” } } implementation ‘com.github.hackware1993:MagicIndicator:1.7.0’ // for androidx AnyLayer: floating floor (pop up) allprojects { repositories { maven { url ‘https://www.jitpack.io’ } } } implementation ‘com.github.goweii:AnyLayer:3.6.0-androidx’ androidautosize: screen adaptation scheme `implementation ‘me.jessyan:autosize:1.2.1’` glide: image loading implementation […]