Installing the Latest Version of Go with Bash

Background

Installation of Go without the need to manually download and run an installer or rely on a package manager.

TL;DR

curl -s https://codingwithcody.com/assets/bash_helpers/install_go.sh | sudo bash

Installation

#!/bin/bash

# Fetch the latest version number
LATEST_GO_VERSION=$(curl 'https://go.dev/VERSION?m=text')

# Download the tarball
wget "https://go.dev/dl/$LATEST_GO_VERSION.linux-amd64.tar.gz"

# Clear old installations
rm -rf /usr/local/go

# Unpack the tarball
tar -C /usr/local -xzf $LATEST_GO_VERSION.linux-amd64.tar.gz

# Cleanup the download
rm $LATEST_GO_VERSION.linux-amd64.tar.gz