Skip to content

Instantly share code, notes, and snippets.

@r4ulcl
Created January 5, 2024 19:24
Show Gist options
  • Save r4ulcl/39b7dce42c5e25ce40fdb3516874a608 to your computer and use it in GitHub Desktop.
Save r4ulcl/39b7dce42c5e25ce40fdb3516874a608 to your computer and use it in GitHub Desktop.
InstallGo.sh
#!/bin/bash
# https://www.cyberciti.biz/faq/how-to-install-gol-ang-on-ubuntu-linux/
sudo apt update ; sudo apt install wget -y
VERSION="1.21.5" # go version
ARCH="amd64" # go archicture
cd
# Step 1 – Downloading Go lang binary files
curl -O -L "https://golang.org/dl/go${VERSION}.linux-${ARCH}.tar.gz"
# Instead of curl, one can use wget command too #
wget -L "https://golang.org/dl/go${VERSION}.linux-${ARCH}.tar.gz"
# Step 2 – Using SHA256 checksum to validate go lang
HASH=$(curl -sL https://golang.org/dl/ | grep -A 5 -w "go${VERSION}.linux-${ARCH}.tar.gz" | grep '<td><tt>' | grep -oP '<td><tt>\K[a-fA-F0-9]+(?=</tt></td>)')
actual_hash=$(sha256sum go${VERSION}.linux-${ARCH}.tar.gz | awk '{print $1}')
if [ "$HASH" = "$actual_hash" ]; then
echo "Hashes match. The file is authentic."
else
echo "Hashes do not match. The file may be corrupted or tampered with."
exit 0
fi
# Step 3 – Extracting go lang from the tar.gz file
tar -xf "go${VERSION}.linux-${ARCH}.tar.gz"
sudo chown -R root:root ./go
sudo mv -v go /usr/local
echo '# set up Go lang path #
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin' >> ~/.bash_profile
# Step 5 – Verify go lang installation
source ~/.bash_profile
go install github.com/swaggo/swag/cmd/swag@latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment