Quickly switch MacOS Node versions (HomeBrew)

scenes to be used

When there are many front-end projects being developed at the same time, some of them are old projects that rely on lower versions of packages and need to use a lower version of node; new projects need to use a higher version of node, and then the node version will need to be switched, which is commonly used in windows. nvm, but on mac I still find it very convenient to use HomeBrew to switch. If you don’t know what HomeBrew is, you can check it out first. I understand it to be a software management software, similar to an app store, but you use commands to complete software-related operations.

Steps

  1. I installed node14 and node18 on my computer using homebrew. Currently I am using 18;
  2. As you can see, after the modification, you need to execute source .zshrc to make the configuration file take effect, otherwise the node version cannot be switched. Of course, if you don’t want to execute source .zshrc, you can also restart the computer to take effect, unless you are very busy (manual dog head).
a1@1deMacBook-Air ~ % brew unlink node@18                  
Unlinking /opt/homebrew/Cellar/node@18/18.18.0... 2269 symlinks removed.
a1@1deMacBook-Air ~ % brew link --overwrite --force node@14
Linking /opt/homebrew/Cellar/node@14/14.21.3_1... 3957 symlinks created.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/opt/homebrew/opt/node@14/bin:$PATH"' >> ~/.zshrc
a1@1deMacBook-Air ~ % echo 'export PATH="/opt/homebrew/opt/node@14/bin:$PATH"' >> ~/.zshrc
a1@1deMacBook-Air ~ % node -v    
v18.18.0
a1@1deMacBook-Air ~ % source .zshrc
a1@1deMacBook-Air ~ % node -v      
v14.21.3

以上就是我使用Mac 快速切换node的方法了。

Guess you like

Origin blog.csdn.net/weixin_44019553/article/details/134639294