Created
March 25, 2020 17:12
-
-
Save kfcampbell/c9029888c7271594f6e1486885e73e6b to your computer and use it in GitHub Desktop.
Easily switch Go versions at the command-line.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my amazing colleague @fatih showed me this. saving it here so i don't forget it. | |
function switchgo() { | |
version=$1 | |
if [ -z $version ]; then | |
echo "Usage: switchgo [version]" | |
return | |
fi | |
if ! command -v "go$version" > /dev/null 2>&1; then | |
echo "version does not exist, downloading with commands: " | |
echo " go get golang.org/dl/go${version}" | |
echo " go${version} download" | |
echo "" | |
go get "golang.org/dl/go${version}" | |
go${version} download | |
fi | |
go_bin_path=$(command -v "go$version") | |
ln -sf "$go_bin_path" "$GOBIN/go" | |
echo "Switched to ${go_bin_path}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment