Skip to content

Instantly share code, notes, and snippets.

@IanThomasICT
Last active June 9, 2024 23:15
Show Gist options
  • Select an option

  • Save IanThomasICT/aeaddaa0ac52be947a296aa78e0c35cc to your computer and use it in GitHub Desktop.

Select an option

Save IanThomasICT/aeaddaa0ac52be947a296aa78e0c35cc to your computer and use it in GitHub Desktop.
Shell script to install the latest version of Go on a linux system (AMD64)
LATEST_VERSION=$(curl 'https://go.dev/VERSION?m=text' | head -n1)
if [ ! -n "$LATEST_VERSION" ]
then
echo "Failed to retrieve latest go version"
exit 1
fi
FILE_NAME="$LATEST_VERSION.linux-amd64.tar.gz"
echo "Retrieving tar for latest go version..."
wget https://dl.google.com/go/$FILE_NAME -O $FILE_NAME
MIN_FILE_SIZE=30000000
FILE_SIZE=$(stat -c%s "$FILE_NAME")
if [ $FILE_SIZE -lt $MIN_FILE_SIZE ]; then
echo "Failed to download archive file for latest go version"
exit 1;
fi
# Unzip and install go files according to https://go.dev/doc/install
echo "Clearing current go folder..."
sudo rm -rf /usr/local/go
echo "Unpacking latest go files..."
sudo tar -C /usr/local -xzf $FILE_NAME
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment