Skip to content

Instantly share code, notes, and snippets.

@scottcagno
Last active January 12, 2017 21:51
Show Gist options
  • Select an option

  • Save scottcagno/4987cd7a89fff5b7cd53 to your computer and use it in GitHub Desktop.

Select an option

Save scottcagno/4987cd7a89fff5b7cd53 to your computer and use it in GitHub Desktop.
Download, install, export and stage Go for linux
#!/usr/bin/env bash
# CHANGE THIS TO THE VERSION YOU WANT TO INSTALL
VERSION="1.7.4"
UPDATED="false"
# CHECKING TO SEE IF WE ARE UPDATING OR INSTALLING NEW
CURRENT=`echo \`go version\` | grep -o '1\..'`
if (( ${VERSION##*.} > ${CURRENT##*.} )); then
UPDATED="true"
rm -rf /usr/local/go/*
fi
echo "Downloading golang tarball..."
sudo curl -o go${VERSION}.linux-amd64.tar.gz https://storage.googleapis.com/golang/go${VERSION}.linux-amd64.tar.gz
echo "Extracting and installing into /usr/local/go..."
sudo tar -C /usr/local -xzf go${VERSION}.linux-amd64.tar.gz
if [[ UPDATED -eq "false" ]]; then
exit 0
fi
echo "Creating golang workspace..."
mkdir -p $HOME/code/go/src/github.com/
echo "Exporting golang PATH environment variables..."
echo "\n#GOLANG" >> ~/.bashrc
echo 'export GOPATH=$HOME/code/go' >> ~/.bashrc
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin' >> ~/.bashrc
echo "Successfully installed golang, please run 'source ~/.bashrc | go version'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment