I use windows for my work and I frequently switch between Golang 18 and the latest version. Also I use Git Bash as terminal in my windows. Here is the steps to setup GVM in that. There is a slight difference between the official documentation. Thats why this post.
What official documentation says?
Most of you used this gvm . But this is doesn’t support for windows. So I have found this andrewkroh/gvm: Go Version Manager . Its supports windows as well.
If you are using powershell go with their documentation
[Net.ServicePointManager]::SecurityProtocol = "tls12"
Invoke-WebRequest -URI https://github.com/andrewkroh/gvm/releases/download/v0.5.2/gvm-windows-amd64.exe -Outfile C:\Windows\System32\gvm.exe
gvm --format=powershell 1.23.2 | Invoke-Expression
go version
But there is no documentation for Git bash.
How to do in Git Bash
Install
Open Git Bash.
This is for install gvm and install golang 1.18
mkdir -p ~/bin
curl -sL -o ~/bin/gvm https://github.com/andrewkroh/gvm/releases/download/v0.5.2/gvm-windows-amd64.exe
chmod +x ~/bin/gvm
gvm install 1.18
Setup default Golang
The following will auto add it in your .bashrc
file. This will setup golang 1.18 as default.
cat << "EOF" >> ~/.bashrc
#
# GVM (Go Version Manager) https://github.com/andrewkroh/gvm
#
if which gvm > /dev/null; then
if gvm list | grep -q "1.18"; then
eval "$(gvm --format=bash 1.18)"
fi
fi
EOF
To change Golang
To change the golang to 1.23
from 1.18
on runtime
Install 1.23 if not already installed
gvm install 1.23
To change
eval $(gvm use --format=bash 1.23)