$ vi /etc/profile.d/golang.sh
# 将以下环境变量添加到profile最后面
export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/data/gopath
$ source /etc/profile
#!/bin/bash
wget -c https://studygolang.com/dl/golang/go1.14.3.linux-amd64.tar.gz
tar -C /usr/local -zxvf go1.14.3.linux-amd64.tar.gz
go_etc=/etc/profile.d/golang.sh
touch $go_etc
# shellcheck disable=SC2129
echo "export GO111MODULE=on" >> $go_etc
echo "export GOPROXY=https://goproxy.cn,direct" >> $go_etc
echo "export GOROOT=/usr/local/go" >> $go_etc
echo "export PATH=\$PATH:\$GOROOT/bin" >> $go_etc
echo "export GOPATH=/data/gopath" >> $go_etc
source /etc/profile
go env
网友评论