jackieli123723 / jackieli123723.github.io

✅lilidong 个人博客
9 stars 0 forks source link

centos7中如何安装go #69

Open jackieli123723 opened 5 years ago

jackieli123723 commented 5 years ago

centos7中如何安装go

featured

Go,通常被称为golang是由Google创建的现代开源编程语言。许多流行的应用程序,包括Kubernetes,Docker,Hugo和Caddy,都是用Go编写的。


下载
[root@VM_134_103_redhat go-study]# wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
--2019-01-03 16:44:38--  https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 203.208.40.73, 203.208.40.65, 203.208.40.70, ...
Connecting to dl.google.com (dl.google.com)|203.208.40.73|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 132489256 (126M) [application/octet-stream]
Saving to: ‘go1.10.3.linux-amd64.tar.gz’

100%[====================================================================================================================================================================================================================================>] 132,489,256 2.40MB/s   in 52s    

2019-01-03 16:45:31 (2.45 MB/s) - ‘go1.10.3.linux-amd64.tar.gz’ saved [132489256/132489256]

[root@VM_134_103_redhat go-study]# ll
total 129524
-rw-r--r-- 1 root root 132489256 Jun  8  2018 go1.10.3.linux-amd64.tar.gz
-rw-r--r-- 1 root root        77 Jan  3 16:36 hello.go
下载完成后,使用以下sha256sum命令验证tarball校验和
[root@VM_134_103_redhat go-study]# sha256sum go1.10.3.linux-amd64.tar.gz
fa1b0e45d3b647c252f51f5e1204aba049cde4af177ef9f2181f43004f901035  go1.10.3.linux-amd64.tar.gz
使用该tar命令将tarball解压缩到/usr/local目录
[root@VM_134_103_redhat go-study]# sudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz

现在我们需要通过调整PATH环境变量告诉我们的系统在哪里找到Go可执行文件二进制文件
[root@VM_134_103_redhat ~]# vi /etc/profile
加入到变量环境到最后
export PATH=$PATH:/usr/local/go/bin

[root@VM_134_103_redhat ~]# go version
go version go1.10.3 linux/amd64

运行
[root@VM_134_103_redhat go-study]# go run hello.go 
Hello, World!
[root@VM_134_103_redhat go-study]# 

构建二进制

[root@VM_134_103_redhat go-study]# go build
[root@VM_134_103_redhat go-study]# ll
total 131496
-rw-r--r-- 1 root root 132489256 Jun  8  2018 go1.10.3.linux-amd64.tar.gz
-rwxr-xr-x 1 root root   2011612 Jan  3 16:58 go-study
-rw-r--r-- 1 root root        77 Jan  3 16:36 hello.go
[root@VM_134_103_redhat go-study]# ./go-study 
Hello, World!
[root@VM_134_103_redhat go-study]#