-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-go.sh
56 lines (47 loc) · 1.24 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
while getopts v: flag; do
case "${flag}" in
v) V=$OPTARG ;;
*) echo "WARN: unknown parameter: ${OPTARG}"
esac
done
# Determine the go version
LATEST_VERSION=$(curl -s https://go.dev/dl/?mode=json | jq -r '.[0].version')
if [ -n "$V" ]; then
VERSION="go$V"
else
VERSION="$LATEST_VERSION"
fi
# Determine the operating system
if [[ "$(uname -s)" == "Linux" ]]; then
OS="linux"
elif [[ "$(uname -s)" == "Darwin" ]]; then
OS="darwin"
else
echo "Unsupported operating system"
exit 1
fi
# Determine the architecture
if [[ "$(uname -m)" == "x86_64" ]]; then
ARCH="amd64"
elif [[ "$(uname -m)" == "aarch64" ]]; then
ARCH="arm64"
else
echo "Unsupported architecture"
exit 1
fi
# Install the binaries
curl -L -# -O "https://golang.org/dl/$VERSION.$OS-$ARCH.tar.gz"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "$VERSION.$OS-$ARCH.tar.gz"
rm "$VERSION.$OS-$ARCH.tar.gz"
# Set the path if needed
touch $HOME/.bash_profile
source $HOME/.bash_profile
PATH_INCLUDES_GO=$(grep "$HOME/go/bin" $HOME/.bash_profile)
if [ -z "$PATH_INCLUDES_GO" ]; then
echo "export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> $HOME/.bash_profile
echo "export GOPATH=$HOME/go" >> $HOME/.bash_profile
fi
source $HOME/.bash_profile
go version