Created
June 18, 2024 20:36
-
-
Save Issaminu/c7f1666c381973f07dcfe9c5bd79bd03 to your computer and use it in GitHub Desktop.
Bash script that updates Golang to latest version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
version=$(go version | awk '{print $3}') | |
release=$(wget -qO- "https://golang.org/VERSION?m=text" | head -n 1) | |
if [[ $version == "$release" ]]; then | |
echo "The local Go version ${release} is up-to-date." | |
exit 0 | |
else | |
echo "The local Go version is ${version}. A new release ${release} is available." | |
fi | |
release_file="${release}.linux-amd64.tar.gz" | |
tmp=$(mktemp -d) | |
cd $tmp || exit 1 | |
echo "Downloading https://go.dev/dl/$release_file ..." | |
curl -OL https://go.dev/dl/$release_file | |
install_dir="/usr/local" | |
rm -rf "$install_dir" 2>/dev/null | |
sudo tar -C "$install_dir" -xzf $release_file | |
rm -rf $tmp | |
version=$(go version | awk '{print $3}') | |
echo "Now, local Go version is $version" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment