Last active
December 16, 2023 20:59
-
-
Save D1360-64RC14/37dd122379ae3529b0d1eb7ebcf3d15e to your computer and use it in GitHub Desktop.
Update golang with only one command. REQUIRED program "jq".
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
#!/bin/bash | |
LAST_VERSION_NUMBER=$(curl -s "https://go.dev/dl/?mode=json" | jq ".[0].version" | sed 's/"//g' | sed 's/go//') | |
DOWNLOAD_URL="https://go.dev/dl/go${LAST_VERSION_NUMBER}.linux-amd64.tar.gz" | |
BASE_DIR="/opt/go" | |
FOLDER_NAME="go-${LAST_VERSION_NUMBER}" | |
UNPACK_DST="${BASE_DIR}/${FOLDER_NAME}" | |
if [ -d "${UNPACK_DST}" ]; then | |
echo "Already installed last version ${LAST_VERSION_NUMBER}!" | |
exit 0 | |
fi | |
echo "[*] Installing new Golang '${FOLDER_NAME}' from '${DOWNLOAD_URL}' to '${UNPACK_DST}'..." | |
set -e | |
echo "[1] Downloading new Golang version..." | |
if [ -d "/tmp/go" ]; then | |
echo "[1.1] Cleaning old '/tmp/go'..." | |
/bin/rm -r /tmp/go | |
fi | |
curl -L $DOWNLOAD_URL | tar xz -C /tmp | |
echo | |
echo "[2] Installing '${FOLDER_NAME}'..." | |
sudo mv /tmp/go $UNPACK_DST | |
echo "[3] Linking '${UNPACK_DST}' to '${BASE_DIR}/bin'" | |
sudo /bin/rm $BASE_DIR/bin | |
sudo ln -s ${UNPACK_DST}/bin ${BASE_DIR}/bin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment