Skip to content

Instantly share code, notes, and snippets.

@alexcrownus
Forked from stefanprodan/win10-bash-go-install.sh
Last active October 14, 2016 13:17
Show Gist options
  • Save alexcrownus/b0602104070429a0f66f5b7c40608e7d to your computer and use it in GitHub Desktop.
Save alexcrownus/b0602104070429a0f66f5b7c40608e7d to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
GVERSION="1.7.1"
GFILE="go$GVERSION.linux-amd64.tar.gz"
GOPATH="$HOME/gocode"
GOROOT="/usr/local/go"
if [ -d $GOROOT ]; then
echo "Installation directories already exist $GOROOT"
exit 1
fi
mkdir -p "$GOROOT"
chmod 777 "$GOROOT"
wget https://storage.googleapis.com/golang/$GFILE -O $TMPDIR/$GFILE
if [ $? -ne 0 ]; then
echo "Go download failed! Exiting."
exit 1
fi
tar -C "/usr/local" -xzf $TMPDIR/$GFILE
touch "$HOME/.bashrc"
{
echo '# GoLang'
echo 'export PATH=$PATH:/usr/local/go/bin'
echo 'export GOPATH=$HOME/gocode'
echo 'export PATH=$PATH:$GOPATH/bin'
} >> "$HOME/.bashrc"
source "$HOME/.bashrc"
echo "GOROOT set to $GOROOT"
mkdir -p "$GOPATH" "$GOPATH/src" "$GOPATH/pkg" "$GOPATH/bin" "$GOPATH/out"
chmod 777 "$GOPATH" "$GOPATH/src" "$GOPATH/pkg" "$GOPATH/bin" "$GOPATH/out"
echo "GOPATH set to $GOPATH"
rm -f $TMPDIR/$GFILE
@alexcrownus
Copy link
Author

alexcrownus commented Oct 14, 2016

Install:

curl -s -L <GIST_RAW_URL> | sudo bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment