Skip to content

Instantly share code, notes, and snippets.

@codeliger
Created November 9, 2022 19:06
Show Gist options
  • Save codeliger/4061df95d458769ee5c3c8a60cd66de3 to your computer and use it in GitHub Desktop.
Save codeliger/4061df95d458769ee5c3c8a60cd66de3 to your computer and use it in GitHub Desktop.
A function for .bashrc to update go to latest version
function updatego(){
GOVERSION=`git ls-remote --tags https://go.googlesource.com/go | grep -E "refs\/tags\/go[[:digit:]]*\.[[:digit:]]*(\.[[:digit:]]*)?$" | cut -f2 -- | sort -V | tail -n 1 | cut -d'/' -f3`
FILENAME=$GOVERSION.linux-amd64.tar.gz
FILEPATH="/home/$USER/$FILENAME"
URL=https://golang.org/dl/$FILENAME
echo "Downloading $URL"
echo "Saving to $FILEPATH"
echo "wget -nc -c -O $FILEPATH $URL"
wget -nc -c -O $FILEPATH $URL
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf $FILEPATH
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment