Script to Upgrade to Latest Go version
This is my super simple script to upgrade to a newer Go version. You might find it handy as well.
#!/bin/zsh
GODIR=~/up
function latestGo {
local LATEST=$(curl -s 'https://golang.org/dl/?mode=json' | jq -r '.[0].version')
local INSTALLED=$(go version | awk '{ print $3 }')
if [[ ${INSTALLED} == ${LATEST} ]]; then
echo Go is up to date, running ${LATEST} >&2
exit 0
fi
echo Upgrading Go from ${INSTALLED} to ${LATEST} >&2
local GOLANG=https://dl.google.com/go/${LATEST}.linux-amd64.tar.gz
local TAR=$(basename $GOLANG)
( cd ${GODIR}
echo Downloading and extracting: $GOLANG >&2
wget -q $GOLANG && rm -rf go && tar xvfz ${TAR}
)
}
latestGo
Read other posts