Skip to content

Instantly share code, notes, and snippets.

@chosenonehacks
Last active February 20, 2023 12:11
Show Gist options
  • Save chosenonehacks/6d7a2ccecf3ec21113ecbfdd58ceb4ac to your computer and use it in GitHub Desktop.
Save chosenonehacks/6d7a2ccecf3ec21113ecbfdd58ceb4ac to your computer and use it in GitHub Desktop.
Get latest GO and install into your linux
#!/bin/bash
#run as sudo
if [ "$EUID" -ne 0 ]
then echo "Please run as sudo"
exit
fi
#get latest GO and install latest into your linux
printf "Runs as sudo...\n";
printf "Checking latest Go version...\n";
LATEST_GO_VERSION="$(curl --silent https://go.dev/VERSION?m=text)";
LATEST_GO_DOWNLOAD_URL="https://golang.org/dl/${LATEST_GO_VERSION}.linux-amd64.tar.gz "
# remove previous installation
printf "Removing previous installations...\n"
rm -rf /usr/local/go
printf "Cd to home ($USER) directory \n"
cd "/home/$USER"
printf "Downloading ${LATEST_GO_DOWNLOAD_URL}\n\n";
curl -OJ -L --progress-bar https://golang.org/dl/${LATEST_GO_VERSION}.linux-amd64.tar.gz
printf "Extracting GO...\n\n";
tar -C /usr/local -xzf ${LATEST_GO_VERSION}.linux-amd64.tar.gz
printf "Installing GCC...\n\n";
apt-get install gcc -y
printf "Adding GO path to \$PATH in ~/.profile\n\n"
echo "export PATH=$PATH:/usr/local/go/bin" >> /home/$SUDO_USER/.profile
source /home/$SUDO_USER/.profile
go version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment