Skip to content

Instantly share code, notes, and snippets.

@bencromwell
Created April 7, 2021 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bencromwell/3909b597891962746cde79e1842f5efa to your computer and use it in GitHub Desktop.
Save bencromwell/3909b597891962746cde79e1842f5efa to your computer and use it in GitHub Desktop.
upgrade Go to the latest available release
#!/bin/bash
CURRENT=$(go version | awk '{print $3}')
LATEST=$(curl --silent https://golang.org/VERSION?m=text)
if [[ "${CURRENT}" == "${LATEST}" ]]; then
echo "You're already using the latest version: ${CURRENT}"
exit 0
fi
TGZ="${LATEST}.linux-amd64.tar.gz"
wget https://golang.org/dl/${TGZ}
if [[ $? -ne 0 ]]; then
echo "Failed to download"
exit 1
fi
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf ${TGZ}
rm ${TGZ}
go version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment