Last active
June 30, 2018 17:16
-
-
Save donaldsteele/eadd7a0fefc3b136bac214a3f2789edd to your computer and use it in GitHub Desktop.
install golang on ubuntu server base install
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
| #!/bin/bash | |
| set -e | |
| GVERSION="1.10.3" | |
| GFILE="go$GVERSION.linux-amd64.tar.gz" | |
| GOPATH="$HOME/go" | |
| GOROOT="/usr/local/go" | |
| TMPDIR=/tmp | |
| apt-get update | |
| apt-get -y upgrade | |
| apt-get -y install build-essential git | |
| mkdir -p "$GOROOT" | |
| chmod 777 "$GOROOT" | |
| #Download Latest Go | |
| GOURLREGEX='https://dl.google.com/go/go[0-9\.]+\.linux-amd64.tar.gz' | |
| echo "Finding latest version of Go for AMD64..." | |
| url="$(wget -qO- https://golang.org/dl/ | grep -oP 'https:\/\/dl\.google\.com\/go\/go([0-9\.]+)\.linux-amd64\.tar\.gz' | head -n 1 )" | |
| latest="$(echo $url | grep -oP 'go[0-9\.]+' | grep -oP '[0-9\.]+' | head -c -2 )" | |
| echo "Downloading latest Go for AMD64: ${latest}" | |
| GFILE=go"${latest}".linux-amd64.tar.gz | |
| wget --quiet --continue --show-progress "${url}" -O $TMPDIR/$GFILE | |
| if [ $? -ne 0 ]; then | |
| echo "Go download failed! Exiting." | |
| exit 1 | |
| fi | |
| unset url | |
| unset GOURLREGEX | |
| tar -C "/usr/local" -xzf $TMPDIR/$GFILE | |
| touch "$HOME/.bashrc" | |
| { | |
| echo '# GoLang' | |
| echo 'export PATH=$PATH:/usr/local/go/bin' | |
| echo 'export GOPATH=$HOME/go' | |
| echo 'export PATH=$PATH:$GOPATH/bin' | |
| } >> "$HOME/.bashrc" | |
| source "$HOME/.bashrc" | |
| echo "GOROOT set to $GOROOT" | |
| mkdir -p ${GOPATH}/{bin,pkg,src,out} | |
| chmod -R 777 ${GOPATH} | |
| echo "GOPATH set to $GOPATH" | |
| rm -f $TMPDIR/$GFILE | |
| echo "Install complete , to reload your envrionment type source ~/.bashrc" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment