Skip to content

Instantly share code, notes, and snippets.

@c29r3
Last active August 28, 2021 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save c29r3/3130b5cd51c4a94f897cc58443890c28 to your computer and use it in GitHub Desktop.
Save c29r3/3130b5cd51c4a94f897cc58443890c28 to your computer and use it in GitHub Desktop.
#!/bin/bash
GO_VERSION=$1
if [ "$GO_VERSION" == "" ]; then
GO_VERSION="1.15.6"
fi
echo $GO_VERSION
cd /tmp/ \
&& wget -q https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz \
&& sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go*.tar.gz \
&& rm go$GO_VERSION*.gz
echo "Creating default Go folders"
mkdir -p $HOME/go/bin
if [[ -z "${GOROOT}" ]]; then
echo "GOROOT is undefined --> creating defaut env variables"
echo -e '\nexport PATH=$HOME/go/bin:$PATH
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GO111MODULE=auto
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bashrc;
source $HOME/.bashrc
else
echo "GOROOT env is alredy exists: $GOROOT"
fi
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment