#!/usr/bin/env bash # Confirmation prompt while true; do read -r -p "Would you like to install Go Language? [Y/n] " input case $input in [yY][eE][sS]|[yY]) break ;; [nN][oO]|[nN]) echo "Go installation aborted." exit 0 ;; *) echo "That wasn't an option..." ;; esac done # Check if curl is installed if ! command -v curl &>/dev/null; then echo "curl is required but not installed. Installing curl..." sudo apt update && sudo apt install -y curl fi # Get latest Go version if [ "$(uname -m)" == "x86_64" ]; then ARCH="amd64" elif [ "$(uname -m)" == "armv6l" ]; then ARCH="armv6l" else ARCH="386" fi GO_VERSION=$(curl -sSL https://golang.org/dl/?mode=json | grep -oP '"version":"\K[^"]+' | head -n1) GO_URL="https://golang.org/dl/go$GO_VERSION.linux-$ARCH.tar.gz" # Install Go echo "Downloading and installing Go $GO_VERSION..." curl -fsSL -o "/tmp/go.tar.gz" "$GO_URL" sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf /tmp/go.tar.gz rm -f /tmp/go.tar.gz # Update PATH echo "Updating PATH..." export PATH=$PATH:/usr/local/go/bin echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc # Add to .bashrc for persistent PATH echo "Go $GO_VERSION has been successfully installed."