illustrate:
I have learned the Go language before (probably version 0.9), but later I updated it too quickly and didn't use it much, so it was abandoned. This year, there are projects that need to be developed using Go and picked up again.
This is what I have compiled during the process of learning Go language. I will record it here and make it easier for me to check it in the future.
Operating system: CentOS 6.9_x64
Go language version: 1.8.3
Install go
Here you can install binary directly. Please search for other methods yourself.
1. Download and install go
The command is as follows:
wget /golang/go1.8. --no-check-certificate tar zxvf go1.8. mv go /usr/local/
2. Add environment variables
vim /etc/profile
Add the following content:
export PATH=$PATH:/usr/local/go/bin export GOROOT=/usr/local/go
Make the configuration effective:
[root@localhost ~]# source /etc/profile [root@localhost ~]# go version go version go1.8.3 linux/amd64 [root@localhost ~]#
Use go
Here we introduce the compilation and operation of the Go language with a simple example, and the deeper content will not be discussed for the time being.
File name: Code:
package main import "fmt" func main() { ("Email : Mike_Zhang@") }
Regular compilation and operation
1. Compile the go source code into a binary file through the go build command;
2. Just execute the compiled binary file.
Examples are as follows:
[root@localhost src]# go build [root@localhost src]# ls test1 [root@localhost src]# ./test1 Email : Mike_Zhang@ [root@localhost src]#
Run as script
The go language can directly run programs through go run, and you can use this feature to run go programs scripted.
Method 1:
[root@localhost src]# go run Email : Mike_Zhang@ [root@localhost src]#
Method 2:
Add the following code to the header of the file:
//usr/bin/env go run $0 "$@"; exit
Then give executable permissions through chmod.
Examples are as follows:
[root@localhost src]# cat //usr/bin/env go run $0 "$@"; exit package main import "fmt" func main() { ("Email : Mike_Zhang@") } [root@localhost src]# chmod a+x [root@localhost src]# ./ Email : Mike_Zhang@ [root@localhost src]#
OK, that's all, I hope it will be helpful to you.
The above specific steps for installation and configuration of go1.8 are all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.