Skip to content

Instantly share code, notes, and snippets.

@carlos-moreno
Last active March 18, 2024 15:01
Show Gist options
  • Save carlos-moreno/d3a53e1b840aa4fdce77e2d1015d6625 to your computer and use it in GitHub Desktop.
Save carlos-moreno/d3a53e1b840aa4fdce77e2d1015d6625 to your computer and use it in GitHub Desktop.
Shell script for GO installation
#!/bin/bash
#------------------------------------------------------------------------------------------
# Script Name: go_install.sh
# Creation Date: 01/16/2024
# Update: 18/03/2024
# Author: Carlos Moreno
# Revision: 0.1.1
# Description: Install or update Go version on Linux System
# Requirement: Make the script executable as per the example command below
# chmod +x go_install.sh
# Example of use: ./go_install 1.22.1
#------------------------------------------------------------------------------------------
if [[ -z "$1" ]]; then
echo "Error: Version must be informed"
echo "Example of use: ./go_install.sh 1.22.1"
exit 1
fi
GO_PKG="go${1}.linux-amd64.tar.gz"
echo "Download Go version ${1}"
curl -fLO https://go.dev/dl/${GO_PKG}
if [[ $? -ne 0 ]]; then
echo "Error: Version not found."
exit 1
fi
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf $GO_PKG
if ! [[ `echo $PATH | grep "/usr/local/go"` ]]; then
echo -e "export PATH=\$PATH:/usr/local/go/bin\n" >> /home/$USER/.profile
fi
source /home/$USER/.profile
rm $GO_PKG
go version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment