Last active
July 1, 2022 13:37
-
-
Save AnomalRoil/48d557f86c25844320a6b13bf16fd50f to your computer and use it in GitHub Desktop.
The `go switch` function allows you to easily switch you current Go version
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
# to add to your ~/.bashrc or your ~/.zshrc file. Usage: $ go switch 1.18.1 | |
function go() { | |
case $* in | |
switch* ) | |
shift 1 | |
gobindir=$(go env GOBIN) | |
# adapt to a valid directory at the beginning of your $PATH if you're not on systemd | |
homebindir=$(systemd-path user-binaries) | |
go install golang.org/dl/go"$@"@latest | |
$gobindir/go"$@" download | |
ln -sf $gobindir/go"$@" $homebindir/go | |
echo "$@ was symlinked to $homebindir/go ; You can run 'go version' to check." | |
;; | |
* ) | |
command go "$@" | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo:
