Last active
November 2, 2023 08:59
-
-
Save alexedwards/8cf2b9ad22dd7adfff5a3af580124620 to your computer and use it in GitHub Desktop.
Bash script to update Go on linux-amd64 (generated using Chat GPT)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the version argument is provided | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <go_version>" | |
exit 1 | |
fi | |
# Version number provided as an argument | |
version="$1" | |
# URL of the file to download | |
url="https://go.dev/dl/go$version.linux-amd64.tar.gz" | |
# Directory to store the downloaded file | |
download_dir="/tmp" | |
# Ensure the download directory exists | |
mkdir -p $download_dir | |
# Download the file | |
echo "Downloading $url..." | |
if ! curl -o "$download_dir/go$version.linux-amd64.tar.gz" -L "$url"; then | |
echo "Failed to download the file. Exiting." | |
exit 1 | |
fi | |
# Remove the existing Go installation | |
echo "Removing existing Go installation..." | |
sudo rm -rf /usr/local/go | |
# Extract the downloaded archive to /usr/local | |
echo "Extracting the downloaded file to /usr/local..." | |
sudo tar -C /usr/local -xzf "$download_dir/go$version.linux-amd64.tar.gz" | |
# Check if the extraction was successful | |
if [ $? -eq 0 ]; then | |
echo "Go $version has been successfully installed." | |
else | |
echo "Failed to install Go. Please check the download and extraction process." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment