Skip to content

Instantly share code, notes, and snippets.

@v3rlly
Last active May 12, 2021 16:35
Show Gist options
  • Save v3rlly/502debce2eef17c9570553046aa316db to your computer and use it in GitHub Desktop.
Save v3rlly/502debce2eef17c9570553046aa316db to your computer and use it in GitHub Desktop.
Golang one line autosetup using curl
#!/usr/bin/bash
####################################################
# Golang autosetup script
#
# usage:
# v=GOLANG_VERSION curl -s THIS_RAW_GIST | bash
#
# copy & paste:
# v=1.16.4 curl -s https://gist.githubusercontent.com/v3rlly/502debce2eef17c9570553046aa316db/raw/go_autosetup.sh | bash
####################################################
v=$(test $goversion && echo $goversion || echo "1.16.4")
download_output="/tmp/go$v.linux-amd64.tar.gz"
echo -e "\nDownloading Golang $v to $download_output"
wget --https-only --no-verbose --show-progress "https://golang.org/dl/go$v.linux-amd64.tar.gz" -O $download_output
echo -e "\nExtracting Files to /usr/local/go"
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf $download_output
echo -e "\nSetting up environment variables on $HOME/.profile"
touch $HOME/.profile && mkdir -p $HOME/go
echo '# Golang environment variables' >> $HOME/.profile
echo 'export GOROOT=/usr/local/go' >> $HOME/.profile
echo 'export GOPATH=$HOME/go' >> $HOME/.profile
echo 'export PATH=$GOPATH/bin:$GOROOT/bin:$PATH' >> $HOME/.profile
echo -e "\nInstall Complete! \nExecute \"source \$HOME/.profile\" to apply settings"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment