Skip to content

Instantly share code, notes, and snippets.

@danielhavir
Last active March 29, 2021 23:53
Show Gist options
  • Save danielhavir/d8df1a260a2c042a01c48303ca3967c7 to your computer and use it in GitHub Desktop.
Save danielhavir/d8df1a260a2c042a01c48303ca3967c7 to your computer and use it in GitHub Desktop.
Install/Uninstall Golang (https://golang.org/)
#!/bin/bash
# Resource 1: https://golang.org/doc/install#install
# Resource 2: https://alexatnet.com/install-go-on-raspberry-pi/
version="1.12"
machine=`uname -m`
bold=$(tput bold)
yellow=$(tput setaf 3)
green=$(tput setaf 2)
normal=$(tput sgr0)
if [ $machine == armv7l ]
then
echo "Arch: $machine"
tarfile="go$version.linux-armv6l.tar.gz"
elif [ $machine == x86_64 ]
then
os=`uname`
if [ $os == "Linux" ]
then
echo "Arch: $os $machine"
tarfile="go$version.linux-amd64.tar.gz"
elif [ $os == "Darwin" ]
then
echo "Arch: $os $machine"
tarfile="go$version.darwin-amd64.tar.gz"
fi
else
tput setaf 1; tput bold; echo "Unknown CPU architecture $machine"; tput sgr0
echo "Visit https://golang.org/dl/"
exit 0
fi
echo "####"
url="https://dl.google.com/go/$tarfile"
echo "${bold}Downloading${normal} $url"
wget $url
echo "####"
# The following command needs sudo privileges
echo "Extracting $tarfile, sudo privileges required:"
sudo tar -C /usr/local -xzf $tarfile
echo "####"
echo "${green}Go successfully installed${normal}"
echo "Export PATH ${bold}export PATH=\$PATH:/usr/local/go/bin${normal}"
echo "To set path automatically on next login, add ${yellow}${bold}export PATH=\$PATH:/usr/local/go/bin${normal} to ${yellow}${bold}~/.profile${normal}"
# Remove the tar file
rm -f $tarfile
#!/bin/bash
# Resource: https://golang.org/doc/install#uninstall
# The following needs sudo priviliges:
rm -rf /usr/local/go
tput setaf 3; tput bold
echo """You should also remove the Go bin directory from your PATH environment variable."""
echo """Under Linux and FreeBSD you should edit /etc/profile or $HOME/.profile."""
echo """If you installed Go with the macOS package then you should remove the /etc/paths.d/go file."""
tput sgr0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment