bash -c "$(curl -fsSL https://raw.githubusercontent.com/rajibdpi/go-installer/main/install-go.sh)" bash -c "$(wget -qO- https://raw.githubusercontent.com/rajibdpi/go-installer/main/install-go.sh)"
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
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
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 versionInstead of reinstalling manually every time:
go env -w GOTOOLCHAIN=autoAuto 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