Last active
January 12, 2017 21:51
-
-
Save scottcagno/4987cd7a89fff5b7cd53 to your computer and use it in GitHub Desktop.
Download, install, export and stage Go for linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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