Last active
March 15, 2019 11:22
-
-
Save hugows/e7f172846b7f20eed442b36c4095bddf to your computer and use it in GitHub Desktop.
script to update go to new version on linux ubuntun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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