Created
March 30, 2022 23:22
-
-
Save samson4649/f70641ab09ca706c57c46d52994c69f3 to your computer and use it in GitHub Desktop.
GoLang Latest Installer
This file contains 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
#!/bin/bash | |
# check that root is running | |
if [ "${EUID}" -ne 0 ]; then | |
echo "This script needs to be run as root. Exiting..." | |
exit 1 | |
fi | |
# get current version of go | |
current=$(go version | cut -d' ' -f3) | |
# get latest version filename from go.dev | |
filename=$(curl -sSL 'https://go.dev/dl/?mode=json' \ | |
| jq '.[0]' \ | |
| grep filename \ | |
| grep linux-amd64 \ | |
| cut -d'"' -f4) | |
# format latest version filename to get version only | |
target=$(echo ${filename} | sed -E 's/(.+)\.linux.*/\1/') | |
# check if latest version is already installed | |
if [ "${current}" = "${target}" ]; then | |
echo "Latest version already installed" | |
exit 0 | |
fi | |
# move to tmp and download the latest release | |
cd /tmp && wget https://go.dev/dl/${filename} | |
# remove existing and install latest version (code from go.dev website) | |
rm -rf /usr/local/go \ | |
&& tar -C /usr/local -xzf ${filename} \ | |
&& echo "Successfully installed ${target}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment