#!/bin/bash # #*************************************************************************** # Author: liwanggui # Date: 2021-08-13 # FileName: install-go.sh # Description: install go lange # Copyright (C): 2021 All rights reserved #*************************************************************************** # version="1.24.2" pkgname="go${version}.linux-amd64.tar.gz" function install_go () { if [ -d "/usr/local/go" ]; then echo "Go already installed" exit 1 fi cd /usr/local/src if [ ! -f "$pkgname" ]; then wget https://golang.google.cn/dl/$pkgname -O $pkgname fi tar xzf $pkgname -C /usr/local/ } function config_go () { echo ' export GOROOT="/usr/local/go" export GOPATH="$HOME/go" export PATH="$PATH:$GOROOT/bin"' >> ~/.bashrc /usr/local/go/bin/go env -w GO111MODULE=on /usr/local/go/bin/go env -w GOPROXY="https://goproxy.cn,direct" echo echo ">>> source ~/.bashrc" echo } function main () { if [[ $(uname -s) != "Linux" ]];then echo "不支持此系统平台,只支持 linux 系统" exit 1 fi case "$1" in config) config_go ;; *) install_go config_go ;; esac } main $@