This repository has been archived on 2024-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
thelinuxlist/scripts/unattended/goinstall.sh

37 lines
1020 B
Bash

#!/usr/bin/env bash
# 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 || {
echo "Failed to install curl. Exiting."
exit 1
}
fi
# Get latest Go version
ARCH=$(uname -m)
case $ARCH in
"x86_64") ARCH="amd64" ;;
"armv6l") ARCH="armv6l" ;;
*) ARCH="386" ;;
esac
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..."
sudo rm -rf /usr/local/go
sudo curl -fsSL "$GO_URL" | sudo tar -C /usr/local -xz || {
echo "Failed to download and install Go. Exiting."
exit 1
}
# Update PATH
echo "Updating PATH..."
echo 'export PATH=$PATH:/usr/local/go/bin' | sudo tee -a /etc/profile.d/go.sh >/dev/null
source /etc/profile.d/go.sh
echo "Go $GO_VERSION has been successfully installed."