Skip to content

Instantly share code, notes, and snippets.

@hugows
Last active March 15, 2019 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugows/e7f172846b7f20eed442b36c4095bddf to your computer and use it in GitHub Desktop.
Save hugows/e7f172846b7f20eed442b36c4095bddf to your computer and use it in GitHub Desktop.
script to update go to new version on linux ubuntun
#!/usr/bin/env bash
# Original author: Ravi Teja Pothana (@RaviTezu)
# Hugo: removed stuff I didn't need on Linux
set -e
GO_VERSION="invalid"
GO_ROOT=/usr/local/go
function usage {
printf "./update_go.sh <version> \n"
printf "Example: ./update_go.sh 1.12.1 \n"
exit 1
}
if [ -z "$1" ]; then
usage
else
GO_VERSION=$1
fi
# Function to install golang and setup the env.
function install {
echo
PACKAGE=go$GO_VERSION.linux-amd64.tar.gz
pushd /tmp > /dev/null
echo
if [ ! -f $PACKAGE ]; then
echo "...... [ Downloading ]"
wget https://dl.google.com/go/$PACKAGE
if [ $? -ne 0 ]; then
echo "Failed to Download the package! Exiting."
exit 1
fi
else
echo "...... [ Package already downloaded, using it ]"
fi
# Check if there's any older version of GO installed on the machine.
if [ -d $GO_ROOT ]; then
echo "...... [ Removing an older version of GO ]"
sudo rm -rf /usr/local/go
fi
echo "...... [ Installing ]"
sudo tar -C /usr/local -xzf $PACKAGE
rm -rf $PACKAGE
popd > /dev/null
echo "...... [ Installed ]"
exit 0
}
echo "...... [ Welcome ]"
install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment