Skip to content

Instantly share code, notes, and snippets.

@rajibdpi
Last active February 15, 2026 15:13
Show Gist options
  • Select an option

  • Save rajibdpi/77ad41a7643056fba4fa6f3549f0cd33 to your computer and use it in GitHub Desktop.

Select an option

Save rajibdpi/77ad41a7643056fba4fa6f3549f0cd33 to your computer and use it in GitHub Desktop.
Single command to install go in macOS and Linux

From github using curl:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/rajibdpi/go-installer/main/install-go.sh)" 

From github using wget:

bash -c "$(wget -qO- https://raw.githubusercontent.com/rajibdpi/go-installer/main/install-go.sh)"
  

Linux:

GO_VERSION=$(curl -fsSL https://go.dev/VERSION?m=text | head -n1 | awk '{print $1}') && wget -q https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz && sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf ${GO_VERSION}.linux-amd64.tar.gz && echo 'export PATH=/usr/local/go/bin:$PATH' | sudo tee /etc/profile.d/go.sh > /dev/null && source /etc/profile.d/go.sh && go version

macOS (Apple Silicon):

GO_VERSION=$(curl -fsSL https://go.dev/VERSION?m=text | head -n1 | awk '{print $1}') && wget -q https://go.dev/dl/${GO_VERSION}.darwin-arm64.tar.gz && sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf ${GO_VERSION}.darwin-arm64.tar.gz && echo 'export PATH=/usr/local/go/bin:$PATH' >> ~/.zshrc && source ~/.zshrc && go version

macOS (Intel):

GO_VERSION=$(curl -fsSL https://go.dev/VERSION?m=text | head -n1 | awk '{print $1}') && wget -q https://go.dev/dl/${GO_VERSION}.darwin-amd64.tar.gz && sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf ${GO_VERSION}.darwin-amd64.tar.gz && echo 'export PATH=/usr/local/go/bin:$PATH' >> ~/.zshrc && source ~/.zshrc && go version

Instead of reinstalling manually every time:

go env -w GOTOOLCHAIN=auto

Auto Detect OS Linux or macOS:

set -e; GO_VERSION=$(curl -fsSL https://go.dev/VERSION?m=text | head -n1 | awk '{print $1}'); OS=$(uname -s | tr '[:upper:]' '[:lower:]'); ARCH=$(uname -m); case "$ARCH" in x86_64|amd64) ARCH=amd64 ;; arm64|aarch64) ARCH=arm64 ;; *) echo "Unsupported arch: $ARCH"; exit 1 ;; esac; TARBALL="${GO_VERSION}.${OS}-${ARCH}.tar.gz"; URL="https://go.dev/dl/${TARBALL}"; (command -v wget >/dev/null && wget -q "$URL") || curl -fsSLO "$URL"; sudo rm -rf /usr/local/go; sudo tar -C /usr/local -xzf "$TARBALL"; rm -f "$TARBALL"; SHELL_NAME=$(basename "${SHELL:-}"); [ -z "$SHELL_NAME" ] && SHELL_NAME=$(basename "$(ps -p $$ -o comm= 2>/dev/null || echo sh)"); PROFILE="$HOME/.profile"; [ "$SHELL_NAME" = "zsh" ] && PROFILE="$HOME/.zshrc"; [ "$SHELL_NAME" = "bash" ] && PROFILE="$HOME/.bashrc"; grep -q '/usr/local/go/bin' "$PROFILE" 2>/dev/null || echo 'export PATH=/usr/local/go/bin:$PATH' >> "$PROFILE"; export PATH=/usr/local/go/bin:$PATH; go version

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