Skip to content

Instantly share code, notes, and snippets.

@R0X4R
Last active August 1, 2023 08:41
Show Gist options
  • Save R0X4R/bf7b8cb7b3aeade861599e4bf7754222 to your computer and use it in GitHub Desktop.
Save R0X4R/bf7b8cb7b3aeade861599e4bf7754222 to your computer and use it in GitHub Desktop.
Go language installer for linux and debian systems.
#!/usr/bin/env bash
go_version=$(curl -ks https://golang.org/VERSION?m=text)
red_color="\e[31m"
green_color="\e[32m"
no_color="\e[0m"
type -P go &> /dev/null && echo -e "Current go version is ${green_color}$(go version | awk '{print $3}')${no_color}" || echo -e "${red_color}Go is not installed on your system${no_color}"
echo -e "Downloading latest go into your system - version ${green_color}${go_version}${no_color}"
sudo apt purge --auto-remove golang-go 2> /dev/null &> /dev/null
sudo apt clean &> /dev/null
wget https://dl.google.com/go/${go_version}.linux-amd64.tar.gz -q --no-check-certificate 2> /dev/null
rm -rf /usr/local/go && tar -C /usr/local -xzf ${go_version}.linux-amd64.tar.gz
sudo cp /usr/local/go/bin/go /usr/bin/
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$GOPATH/bin:$GOROOT/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
go version | grep -q "${go_version}" && echo -e "Go installed successfully" || echo -e "Getting some errors while installing go please install it manually"
type -P go &> /dev/null && go help || exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment