Golang安装

Posted by 胡伟煌 on 2017-09-16

1. install-go.sh

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
38
39
40
41
42
43
#!/bin/bash
set -x
set -e

# default version
VERSION=$1
VERSION=${VERSION:-1.14.6}

PLATFORM=$2
PLATFORM=${PLATFORM:-linux}

GOROOT="/usr/local/go"
GOPATH=$HOME/gopath
GO_DOWNLOAD_URL="https://golang.org/dl"

# download and install
case ${PLATFORM} in
"linux")
wget ${GO_DOWNLOAD_URL}/go${VERSION}.${PLATFORM}-amd64.tar.gz
tar -C /usr/local -xzf go${VERSION}.${PLATFORM}-amd64.tar.gz
;;
"mac")
PLATFORM="darwin"
wget ${GO_DOWNLOAD_URL}/go${VERSION}.${PLATFORM}-amd64.tar.gz
tar -C /usr/local -xzf go${VERSION}.${PLATFORM}-amd64.tar.gz
;;
*)
echo "platform not found"
;;
esac

# set golang env
cat >> $HOME/.bashrc << EOF
# Golang env
export GOROOT=/usr/local/go
export GOPATH=\$HOME/gopath
export PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin
EOF

source $HOME/.bashrc

# mkdir gopath
mkdir -p $GOPATH/src $GOPATH/pkg $GOPATH/bin

2. 安装

1
2
chmod +x install-go.sh
./install-go.sh 1.14.6 linux

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

参考:



支付宝打赏 微信打赏

赞赏一下