Do you need to run brew unlink / brew link before / after brew switch?
According to this link https://docs.brew.sh/Tips-N'-Tricks#activate-a-previously-installed-version-of-a-formula brew switch is activate a previously installed version of a formula.
Looks like I have some 'system' python installed(it's installed under /usr/bin/python3), that was not installed with brew, I can see it if I do brew unlink python@3.9 and brew unlink python@3.7:
python -V
Python 3.7.3
/usr/bin/python3 -V
Python 3.7.3
which python3
/usr/bin/python3
Then I switch to python@3.9:
brew switch python@3.9 3.9.0_1
python -V
Python 3.9.0
Then I switch to python@3.7:
brew switch python@3.7 3.7.9
python -V
Python 3.9.0
but it still show me Python 3.9.0, ls -l /usr/local/bin | grep python3 shows me python3.9 too.
I also tried to unlink all brew python packages before each brew switch test:
brew unlink python@3.7 && brew unlink python@3.9
brew switch python@3.7 3.7.9
python -V
Python 3.7.3
brew unlink python@3.7 && brew unlink python@3.9
brew switch python@3.9 3.9.0_1
python -V
Python 3.9.0
So seems for some reason it automatically links python@3.9 on brew switch and don't do it for python@3.7, why? Is brew switch have brew unlink / brew link inside it or should it be done manually?
Can I just do brew unlink / brew link to switch python version?
Update:
Seems newer versions of brew don't have switch:
Error: Calling `brew switch` is disabled! Use `brew link` @-versioned formulae instead.
brew --version
Homebrew 2.7.7
Homebrew/homebrew-core (git revision 918f0; last commit 2021-02-04)
Homebrew/homebrew-cask (git revision 2b83c; last commit 2021-02-04)
So now it should be something like this:
brew unlink python@3.7 && brew unlink python@3.9
brew link python@3.7
python -V
Python 3.7.9