Skip to content

Instantly share code, notes, and snippets.

@pivaldi
Forked from theaog/update-golang.sh
Last active August 25, 2025 12:40
Show Gist options
  • Save pivaldi/f153b36cf2c9bdeaacd37fbcf2d0a3ea to your computer and use it in GitHub Desktop.
Save pivaldi/f153b36cf2c9bdeaacd37fbcf2d0a3ea to your computer and use it in GitHub Desktop.
update-golang.sh
#!/usr/bin/env bash
set -e
tmp=$(mktemp -d)
pushd "$tmp" || exit 1
function cleanup {
popd || exit 1
rm -rf "$tmp"
}
trap cleanup EXIT
version=$(go tool dist version)
release=$(wget -qO- "https://golang.org/VERSION?m=text")
release_file="${release}.linux-amd64.tar.gz"
if [[ $version == "$release" ]]; then
echo "local Go version ${release} is latest."
exit 0
else
echo "local Go version ${version}, new release ${release} is available."
fi
echo "Downloading https://go.dev/dl/$release_file ..."
curl -OL https://go.dev/dl/"$release_file"
goroot=$(go env |grep GOROOT |cut -d'=' -f2 |tr -d '"')
echo "removing folder $goroot"
sudo rm -f "$goroot"
sudo tar -C "${goroot//go}" -xzf "$release_file"
version=$(go tool dist version)
echo "local Go version is $version (latest)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment