1. install-go.sh

  1. #!/bin/bash
  2. # for linux
  3. set -x
  4. set -e
  5. # default version: 1.10.3
  6. VERSION=$1
  7. VERSION=${VERSION:-1.10.3}
  8. GOROOT="/usr/local/go"
  9. GOPATH=$HOME/gopath
  10. # download and install
  11. wget https://dl.google.com/go/go${VERSION}.linux-amd64.tar.gz
  12. tar -C /usr/local -xzf go${VERSION}.linux-amd64.tar.gz
  13. # set golang env
  14. cat >> $HOME/.bashrc << EOF
  15. # Golang env
  16. export GOROOT=/usr/local/go
  17. export GOPATH=\$HOME/gopath
  18. export PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin
  19. EOF
  20. source $HOME/.bashrc
  21. # mkdir gopath
  22. mkdir -p $GOPATH/src $GOPATH/pkg $GOPATH/bin

2. 安装

  1. chmod +x install-go.sh
  2. ./install-go.sh 1.10.3

更多版本号可参考:https://golang.org/dl/

参考: