Last active
December 17, 2025 14:22
-
-
Save qrkourier/0cc1a6a6d036125f6cefe715c90402e4 to your computer and use it in GitHub Desktop.
place the latest Go distribution in /opt/golang so we can link to it with alternatives
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 | |
| set -euxo pipefail | |
| command -v go &>/dev/null && INSTALLED_VERSION=$(go version | grep -Po '.*go(\s+)?\K\d+\.\d+(\.\d+)\s+linux/.*' | sed -E 's|\s+linux/.*||g') | |
| LATEST_GOLANG=$(wget -qO- "https://go.dev/VERSION?m=text" | grep -Po '^go(\s+)?\K\d+\.\d+(\.\d+)?$') | |
| [[ $LATEST_GOLANG == ${INSTALLED_VERSION:-} ]] && exit 0 | |
| sleep 2 | |
| cd $(mktemp -d) | |
| LATEST_GOLANG_ARCH=go${LATEST_GOLANG}.linux-$(dpkg --print-architecture).tar.gz | |
| wget -q https://go.dev/dl/${LATEST_GOLANG_ARCH} | |
| sudo mkdir -p /opt/golang/go${LATEST_GOLANG} | |
| if tar -tf ./${LATEST_GOLANG_ARCH} | head -n 1 | grep -q '^go/'; then | |
| sudo tar -xf ./${LATEST_GOLANG_ARCH} --directory=/opt/golang/go${LATEST_GOLANG} --strip-components=1 | |
| else | |
| sudo tar -xf ./${LATEST_GOLANG_ARCH} --directory=/opt/golang/go${LATEST_GOLANG} | |
| fi | |
| sudo update-alternatives --install /usr/local/go goroot /opt/golang/go${LATEST_GOLANG} 50 | |
| sudo update-alternatives --set goroot /opt/golang/go${LATEST_GOLANG} | |
| sudo ln -sfvn /opt/golang/go${LATEST_GOLANG} /opt/goroot | |
| go version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment