Skip to content

Instantly share code, notes, and snippets.

@lacunoc
Created December 28, 2021 12:15
Show Gist options
  • Save lacunoc/d643d93c15800a015e54b950d5b4ef9a to your computer and use it in GitHub Desktop.
Save lacunoc/d643d93c15800a015e54b950d5b4ef9a to your computer and use it in GitHub Desktop.
Switch golang version on demand
alias gsv="source /usr/local/bin/go_switch_version.sh"
#!/usr/bin/env zsh
if [ $# -eq 0 ]; then
echo "No go version provided"
exit 1
fi
VERSION=$1
ALIAS_FOUND=`grep -c "alias go" ~/.zprofile`
if [ "$VERSION" != "latest" ]
then
sudo go install golang.org/dl/go${VERSION}@latest
go${VERSION} download
else
VERSION=""
fi
sed -i '' '/^alias go.*$/d' ~/.zprofile
echo "alias go=/usr/local/go/bin/go${VERSION}" >> ~/.zprofile
source ~/.zprofile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment