如何在一台机器上使用多个版本的Node?
我的任务是更新当前为 v14.18.0 的大型存储库的节点版本,我可以在包和节点的版本问题最小化的情况下执行此操作的最佳方法是什么?
I am tasked to update the node version for a huge repository which is currently v14.18.0, what is the best way I can go about doing that with minimal version issues with packages and node?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以安装NVM来安装多个版本的节点并在它们之间切换:
https://github.com/nvm-sh/nvm
You can install NVM to install multiple version of node and switch between them :
https://github.com/nvm-sh/nvm
使用 Homebrew - Mac OS 使用
Homebrew 安装节点版本管理器 (NVM)。在终端中运行以下命令:
安装完成后,打开您的配置文件(nano ~/.bash_profile、nano ~/.zshrc、nano ~/.profile 或 nano ~/.bashrc),然后添加以下内容末尾添加几行:
通过将以上几行添加到您的个人资料页面,您可以在终端中运行 nvm 命令。如果不添加上述行,则在终端中运行 nvm 命令时会出现错误。更进一步,您需要重新启动终端才能在终端中使用 nvm 命令。
另外,运行此命令
source ~/.nvm/nvm.sh
如果在新终端中 nvm 不起作用,请尝试使用此命令
nano ~/ 将其添加到 ~/.zshrc 中.zshrc
NVM 命令
现在您已经安装了 NVM,让我们看看一些最有用的命令。
nvm ls 显示所有版本。
Eg
nvm use v20.6.0
安装新版本假设 Node 版本为 20。
安装完所需的 Node 版本后,可以通过运行以下命令来使用它:
nvm使用后,您可以查看版本:
通过运行上述命令,nvm将Node版本切换到您指定的版本。
Using Homebrew - Mac OS
Install the Node Version Manager (NVM) with Homebrew. Run the below command in your terminal:
After the installation finishes, open your profile file (nano ~/.bash_profile, or nano ~/.zshrc, or nano ~/.profile, or nano ~/.bashrc), and add the following lines to it at the end:
By adding the above lines to your profile page, you can run the nvm command in your terminal. If you don't add the above lines, you will get an error when you run nvm commands in the terminal. Going further, you need to restart your terminal to use the nvm commands in the terminal.
Also, run this command
source ~/.nvm/nvm.sh
If in a new terminal nvm doesn't work then try adding this in ~/.zshrc by using this command
nano ~/.zshrc
NVM commands
Now that you have NVM installed, let's see some of the most useful commands.
nvm ls shows all the versions.
E.g
nvm use v20.6.0
Install the new version suppose node version 20.
After installing the Node version you want, you can use it by running the following command:
After nvm use, you can check the version:
By running above command, nvm switches the Node version to the one you specified.
安装nvm来实现。
对于 macOS,请遵循:
https://www.youtube.com/watch?v=W0CssX7oYmQ
Install nvm to achieve it.
For macOS kindly follow:
https://www.youtube.com/watch?v=W0CssX7oYmQ