1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #!/bin/bash
set -eux
cd $(dirname $0) || exit 1
GO_VERSION=1.22.3 GO_INSTALL_DIR=/opt/go GO_ROOT=${GO_INSTALL_DIR}/${GO_VERSION} GO_PATH=~/go ENV_FILE=~/.profile
wget -c https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz
mkdir -p ${GO_INSTALL_DIR} rm -rf ${GO_INSTALL_DIR}/* tar -zxf go${GO_VERSION}.linux-amd64.tar.gz -C ${GO_INSTALL_DIR}/ mv ${GO_INSTALL_DIR}/go ${GO_ROOT}
sed -i 's/^export PATH=.*\/go\/bin.*$//g' ${ENV_FILE} sed -i '$a export PATH='"${GO_ROOT}"'/bin:'"${GO_PATH}"'/bin:$PATH' ${ENV_FILE}
sed -i '/^$/{N;/\n$/D};' ${ENV_FILE}
${GO_ROOT}/bin/go env -w GO111MODULE=on ${GO_ROOT}/bin/go env -w GOPROXY=https://goproxy.cn,direct ${GO_ROOT}/bin/go env -w GOROOT=${GO_ROOT} ${GO_ROOT}/bin/go env -w GOPATH=${GO_PATH}
|