Last active
September 11, 2025 15:34
-
-
Save zhangyoufu/6c60829af1ac61f80484c954360882a1 to your computer and use it in GitHub Desktop.
Download latest Go release and extract to /opt
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/sh | |
| not_available() { echo -- "$1 is not available"; exit 1; } | |
| unknown_arch() { echo -- "unknown architecture"; exit 1; } | |
| ensure_command_available() { which -- "$1" >/dev/null && return; not_available "$1"; } | |
| ensure_gnu_tar() { tar --version | grep -F 'GNU tar' >/dev/null || not_available 'GNU tar'; } | |
| ensure_command_available curl | |
| ensure_command_available jq | |
| ensure_gnu_tar | |
| case $(uname -o) in | |
| Darwin) OS=darwin;; | |
| GNU/Linux) OS=linux;; | |
| Cygwin|MSYS_NT-*) OS=windows;; | |
| esac | |
| case $(uname -m) in | |
| x86_64) ARCH=amd64;; | |
| aarch64|arm64) ARCH=arm64;; | |
| *) unknown_arch;; | |
| esac | |
| export OS ARCH | |
| FILENAME=$(curl -fsSL 'https://golang.google.cn/dl/?mode=json' | jq -r 'map(select(.stable)) | .[0].files | map(select(.os == env.OS and .arch == env.ARCH)) | .[0].filename') | |
| rm -rf /opt/go | |
| echo "Downloading ${FILENAME}" | |
| curl -fSL "https://dl.google.com/go/${FILENAME}" | tar --extract --gzip --directory=/opt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment