-
-
Save tsujp/1d550fc8b89b9c0a1fad19032c79bbfe 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 hidden or 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