OSX上管理多个版本的Nodejs,并且随意切换

Nodejs的项目经常Node自身的版本不同而无法运行,如果每次都选择卸载掉一个版本的Nodejs再安装另外一个版本的Nodejs,会很费劲,通过如下命令切换。

例如:

# For example

# Install main node version 18
$ brew install node@18


# Add the main version to ~/.zshrc to make started
# (~/.bash_profile if you're using default shell)
$ echo 'export PATH="/usr/local/opt/node@18/bin:$PATH"' >> ~/.zshrc

# Execute updated  
$ source ~/.zshrc

# Check version of installed node
$ node -v
v18.12.1

### Want to witch to node version 14
$ brew install node@14
$ echo 'export PATH="/usr/local/opt/node@14/bin:$PATH"' >> ~/.zshrc

# Execute updated  
$ source ~/.zshrc

  参照:https://medium.com/@fucyber/manage-multiple-node-versions-with-homebrew-and-nvm-2c72d98a9f5a

posted @ 2024-05-09 18:06  West Continent  阅读(9)  评论(0编辑  收藏  举报