Skip to content

Instantly share code, notes, and snippets.

@tebeka
Created January 15, 2020 05:50
Show Gist options
  • Select an option

  • Save tebeka/fe81ed8145d003535e66919ae598012b to your computer and use it in GitHub Desktop.

Select an option

Save tebeka/fe81ed8145d003535e66919ae598012b to your computer and use it in GitHub Desktop.
Update go version
#!/bin/bash
case $1 in
-h | --help ) echo "usage: $(basename $0) VERSION"; exit;;
esac
if [ $# -ne 1 ]; then
1>&2 echo "error: wrong number of arguments"
exit 1
fi
cur=$(go version | awk '{print substr($3, 3)}')
version=$1
echo "updating go to version ${version} (current: ${cur})"
base=go${version}.linux-amd64.tar.gz
url=https://dl.google.com/go/${base}
file=${HOME}/Downloads/${base}
dest=/opt/go${version}
set -e
set -x
echo downloading ${url}
curl -o ${file} ${url}
echo unpacking
rm -fr /tmp/go
tar xz -C /tmp -f ${file}
echo copy and symlink
sudo mv /tmp/go ${dest}
sudo ln -sfn ${dest} /opt/go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment