Use the brew link command, for example run this on terminal:
brew unlink node && brew link node@22
when I want to use Node.jsversion 22.
and then run this on terminal
echo 'export PATH="/usr/local/opt/node@22/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/usr/local/opt/node@22/lib"
export CPPFLAGS="-I/usr/local/opt/node@22/include"