Skip to content

Instantly share code, notes, and snippets.

@restuu
Last active December 5, 2020 01:50
Show Gist options
  • Save restuu/c18e916862f8536c003903f4ac789ac1 to your computer and use it in GitHub Desktop.
Save restuu/c18e916862f8536c003903f4ac789ac1 to your computer and use it in GitHub Desktop.
Install Golang version
#!/bin/bash
# e.g 1.15.4
# ./upgrade_go.sh 1.15.4
version=$1
if [ "$version" == "" ]; then
echo "invalid version"
exit 1
fi
file=go$version.linux-amd64.tar.gz
# download version
echo "download $file..."
curl https://dl.google.com/go/$file -o /tmp/$file
# remove existing go version
echo "removing existing go version..."
[ -d "/usr/local/go" ] && sudo rm -rf /usr/local/go || echo "previous go don't exist"
# extract file
echo "extracting file..."
sudo tar -C /usr/local -xzf /tmp/$file || exit 1
# remove tmp file
echo "removing tmp"
rm /tmp/$file
echo "Add this to your your \$HOME/.profile 'export PATH=\$PATH:/usr/local/go/bin'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment