Skip to content

Instantly share code, notes, and snippets.

@comodoro
Created August 25, 2018 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comodoro/8780dd1c6e2b38665c7302e8e7b52a07 to your computer and use it in GitHub Desktop.
Save comodoro/8780dd1c6e2b38665c7302e8e7b52a07 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
GVERSION="1.11"
GFILE="go$GVERSION.linux-amd64.tar.gz"
GOPATH="$HOME/go"
GOROOT="/usr/local/go"
if [ -d $GOROOT ]; then
echo "Installation directory already exists $GOROOT"
exit 1
fi
mkdir -p "$GOROOT"
chmod 777 "$GOROOT"
TMPDIR=/tmp
wget --no-verbose https://dl.google.com/go/$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/.profile"
{
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" "$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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment