Skip to content

Instantly share code, notes, and snippets.

@giseongeom
Last active March 11, 2023 11:14
Show Gist options
  • Save giseongeom/418b2bcf8d5ad1d8d76c9443fc945af1 to your computer and use it in GitHub Desktop.
Save giseongeom/418b2bcf8d5ad1d8d76c9443fc945af1 to your computer and use it in GitHub Desktop.
Download latest golang (linux-amd64)
#!/usr/bin/env bash
set -e
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi
# go1.19.linux-amd64.tar.gz
export GO_DOWNLOAD_FILE=$(curl -L -Ss https://go.dev/dl/\?mode\=json | jq -r '.[0].files[] | select(.arch == "amd64") | select(.os == "linux") | .filename')
export GO_DOWNLOAD_URL="https://go.dev/dl/${GO_DOWNLOAD_FILE}"
curl -Ss -L -o /tmp/golang.tgz ${GO_DOWNLOAD_URL} \
&& tar zxf /tmp/golang.tgz -C /usr/local \
&& /usr/local/go/bin/go version \
&& echo "golang Installation is Done!" && echo ''
@giseongeom
Copy link
Author

  • Windows 환경에서 최신버전 정보를 구하려면
# windows_amd64 (WindowsPowerShell)
$go_latest_version_list = (Invoke-RestMethod https://go.dev/dl/?mode=json)[0]
$env:GO_DOWNLOAD_FILE = ($go_latest_version_list.files | ? { ($_.os -match 'windows') -and ($_.arch -match 'amd64') -and ($_.kind -match 'archive')}).filename
$env:GO_DOWNLOAD_URL="https://go.dev/dl/" + $env:GO_DOWNLOAD_FILE


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment