下载

地址:https://golang.google.cn/dl/,下载go1.9.1,链接

  1. 下载Linux版本的安装包go1.19.1.src.tar.gz并复制到/usr/local下并解压

[root@hecs-202871 src]# wget https://golang.google.cn/dl/go1.19.1.linux-amd64.tar.gz
--2022-09-11 18:26:59--  https://golang.google.cn/dl/go1.19.1.linux-amd64.tar.gz
Resolving golang.google.cn (golang.google.cn)... 114.250.65.34
Connecting to golang.google.cn (golang.google.cn)|114.250.65.34|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://dl.google.com/go/go1.19.1.linux-amd64.tar.gz [following]
--2022-09-11 18:27:00--  https://dl.google.com/go/go1.19.1.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 114.250.65.33
Connecting to dl.google.com (dl.google.com)|114.250.65.33|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 148820241 (142M) [application/x-gzip]
Saving to: ‘go1.19.1.linux-amd64.tar.gz’

100%[===========================================================>] 148,820,241 11.4MB/s   in 13s    

2022-09-11 18:27:14 (10.7 MB/s) - ‘go1.19.1.linux-amd64.tar.gz’ saved [148820241/148820241]

[root@hecs-202871 src]# ls
debug  go1.19.1.linux-amd64.tar.gz  kernels
[root@hecs-202871 src]# tar -xzf go1.19.1.linux-amd64.tar.gz -C /usr/local
[root@hecs-202871 src]# cd /usr/local
[root@hecs-202871 local]# ls
bin    bttomcat  etc    go         include  lib64    libiconv  nghttp2  openssl111  share  uniagent
btjdk  curl      games  hostguard  lib      libexec  man       openssl  sbin        src
[root@hecs-202871 local]# cd go
[root@hecs-202871 go]# vim /etc/profile
[root@hecs-202871 go]# sorce /etc/profile
-bash: sorce: command not found
[root@hecs-202871 go]# source /etc/profile
[root@hecs-202871 go]# go version
go version go1.19.1 linux/amd64
  1. 增加Linux环境变量并source生效

(1)执行编写环境变量命令

vim /etc/profile

(2)增加下面的配置

export GOPATH=/home/golang/gopath
export GOROOT=/usr/local/go
export GOARCH=386
export GOOS=linux
export GOTOOLS=$GOROOT/pkg/tool
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

(3)source环境变量使之生效

source /etc/profile

经常打开的目录配置下别名

vi ~/.bashrc
alias goroot='cd /usr/local/go'
alias gopath='cd /home/golang/gopath'
source ~/.bashrc

就能直接跳转到配置的目录下了