1.下載
wget https://studygolang.com/dl/golang/go1.13.6.linux-amd64.tar.gz
2.解壓
[root@localhost local]# tar -C /usr/local -xzf go1.13.6.linux-amd64.tar.gz
[root@localhost go]# cd /usr/local
[root@localhost go]# cd /usr/local
[root@localhost local]# ll
drwxr-xr-x 10 root root 272 Jan 10 03:05 go
3.修改環(huán)境變量
[root@localhost local]# vi /etc/profile
末尾增加
export PATH=$PATH:/usr/local/go/bin
[root@localhost local]# source /etc/profile
4.編寫helloworld測試
[root@localhost hello]# vi helloworld.go
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
[root@localhost hello]# go build helloworld.go //編譯
[root@localhost hello]# ll
total 1984
-rwxr-xr-x 1 root root 2025490 Jan 13 11:50 helloworld
-rw-r--r-- 1 root root 82 Jan 13 11:49 helloworld.go
[root@localhost hello]# chmod +x helloworld
[root@localhost hello]# ./helloworld //執(zhí)行
hello, world
因為go是編譯性語言赚窃。一次編譯多處可以執(zhí)行甲棍。所以把helloword拷貝到任何目錄都能正常執(zhí)行枫甲,并且可以脫離go環(huán)境執(zhí)行讼昆。只不過要求操作系統(tǒng)一致。