Skip to content

Instantly share code, notes, and snippets.

@jniltinho
Last active December 23, 2023 00:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jniltinho/8fe13181e161cddda94a8e571a712da9 to your computer and use it in GitHub Desktop.
Save jniltinho/8fe13181e161cddda94a8e571a712da9 to your computer and use it in GitHub Desktop.
Update Golang *Nix
#!/bin/bash
## Update Golang (Linux/Mac)
/usr/local/go/bin/go version
LOCAL_VERSION=$(/usr/local/go/bin/go version|awk '{print $3}')
## Get Last Stable Version
LAST_VERSION=$(curl -s 'https://go.dev/VERSION?m=text'|head -n1)
OS="linux"
ARCH="amd64"
if [[ "$(uname -s)" == "Darwin" ]]; then
OS="darwin"
fi
if [[ "$(uname -m)" == "arm64" ]]; then
ARCH="arm64"
fi
if [[ "$LOCAL_VERSION" == "$LAST_VERSION" ]]; then
echo "Go is up to date"
exit 0
fi
rm -rf /usr/local/go
curl -L --progress-bar "https://go.dev/dl/${LAST_VERSION}.$OS-$ARCH.tar.gz"|tar -C /usr/local/ -xzf -
/usr/local/go/bin/go version
@adell
Copy link

adell commented Nov 17, 2023

#!/bin/bash
## Update Golang (Linux/Mac)

/usr/local/go/bin/go version

## Get Last Stable Version
LAST_VERSION=$(curl -s 'https://go.dev/VERSION?m=text'|head -n1)
OS="linux"
ARCH="amd64"

if [ "$(uname -s)" = "Darwin" ]; then
    OS="darwin"
fi


if [ "$(uname -m)" = "arm64" ]; then
    ARCH="arm64"
fi

GO_LOCAL=$(/usr/local/go/bin/go version | awk '{print $3}' | sed 's/[a-z]//g' | sed 's/\.//g')
LATEST=$(echo $LAST_VERSION | sed 's/[a-z]//g' | sed 's/\.//g')

if [ "$GO_LOCAL" = "$LATEST" ]; then
    echo "Go is up to date"
    exit 0
fi

curl -LO --progress-bar "https://go.dev/dl/${LAST_VERSION}.$OS-$ARCH.tar.gz"
rm -rf /usr/local/go
tar -C /usr/local -xzf ${LAST_VERSION}.$OS-$ARCH.tar.gz
rm -f ${LAST_VERSION}.$OS-$ARCH.tar.gz
/usr/local/go/bin/go version

@jniltinho
Copy link
Author

@adell ficou show, atualizei !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment