下载包
cd ~
wget https://studygolang.com/dl/golang/go1.15.6.linux-amd64.tar.gz
解压&配置环境变量
tar -zxvf go1.15.6.linux-amd64.tar.gz -C /usr/local/
# 修改~/.bashrc添加以下内容
export GOROOT=/usr/local/go #设置为go安装的路径
export GOPATH=/home/gocode #默认安装包的路径
export GOPROXY=https://goproxy.cn,direct
export PATH=$PATH:/usr/local/go/bin
# 修改生效
source ~/.bashrc
效果
[root@centos ~]# go version
go version go1.15.6 linux/amd64
完整脚本
cd ~
wget https://studygolang.com/dl/golang/go1.15.6.linux-amd64.tar.gz
tar -zxvf go1.15.6.linux-amd64.tar.gz -C /usr/local/
sudo tee ~/.bashrc <<-'EOF'
export GOROOT=/usr/local/go #设置为go安装的路径
export GOPATH=/home/gocode #默认安装包的路径
export GOPROXY=https://goproxy.cn,direct
export PATH=$PATH:/usr/local/go/bin
EOF
source ~/.bashrc