File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash -e
2+
3+ # Usage:
4+ # $ install-go.sh # source Go version from go.mod
5+ # $ install-go.sh 1.24.7 # install specific Go version
6+ #
7+ # Description:
8+ # - Download go version and install under /usr/local/go
9+ # - Create symlinks for go and gofmt in /usr/local/bin
10+
11+ VERSION=" ${1:- } "
12+ if [ -z " ${VERSION} " ]; then
13+ DIR=" $( realpath " $( dirname " ${0} " ) " ) "
14+ VERSION=" $( cat " ${DIR} /../../go.mod" | grep " ^go" | sed " s,^go\s,," ) "
15+
16+ echo " Will install Go version from go.mod : ${VERSION} "
17+ fi
18+
19+ # infer ARCH
20+ ARCH=" $( uname -m) "
21+ if uname -m | grep -q x86_64; then ARCH=amd64; fi
22+ if uname -m | grep -q aarch64; then ARCH=arm64; fi
23+
24+ # infer OS
25+ OS=" $( uname -s) "
26+ if uname -s | grep -q Linux; then OS=linux; fi
27+ if uname -s | grep -q Darwin; then OS=darwin; fi
28+
29+ fname=" go${VERSION} .${OS} -${ARCH} .tar.gz"
30+ [ -f " $fname " ] || wget " https://go.dev/dl/go${VERSION} .${OS} -${ARCH} .tar.gz"
31+ sudo tar -C /usr/local -xvzf " ${fname} "
32+ rm " ${fname} "
33+
34+ sudo ln -sf /usr/local/go/bin/go /usr/local/bin/go
35+ sudo ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt
You can’t perform that action at this time.
0 commit comments