如何在一台机器上使用多个版本的Node?

发布于 2025-01-12 16:11:37 字数 73 浏览 2 评论 0原文

我的任务是更新当前为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱人如己 2025-01-19 16:11:37

您可以安装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

木森分化 2025-01-19 16:11:37

使用 Homebrew - Mac OS 使用

Homebrew 安装节点版本管理器 (NVM)。在终端中运行以下命令:

brew install nvm

安装完成后,打开您的配置文件(nano ~/.bash_profile、nano ~/.zshrc、nano ~/.profile 或 nano ~/.bashrc),然后添加以下内容末尾添加几行:

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

通过将以上几行添加到您的个人资料页面,您可以在终端中运行 nvm 命令。如果不添加上述行,则在终端中运行 nvm 命令时会出现错误。更进一步,您需要重新启动终端才能在终端中使用 nvm 命令。

另外,运行此命令 source ~/.nvm/nvm.sh

如果在新终端中 nvm 不起作用,请尝试使用此命令 nano ~/ 将其添加到 ~/.zshrc 中.zshrc

export NVM_DIR="$HOME/.nvm"
. "/usr/local/opt/nvm/nvm.sh"

NVM 命令

现在您已经安装了 NVM,让我们看看一些最有用的命令。

nvm ls

nvm ls 显示所有版本。

nvm use

Eg nvm use v20.6.0

安装新版本假设 Node 版本为 20。

nvm install 20

安装完所需的 Node 版本后,可以通过运行以下命令来使用它:

nvm alias default <node_version>

nvm use

nvm使用后,您可以查看版本:

node -v

通过运行上述命令,nvm将Node版本切换到您指定的版本。

Using Homebrew - Mac OS

Install the Node Version Manager (NVM) with Homebrew. Run the below command in your terminal:

brew install nvm

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:

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

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

export NVM_DIR="$HOME/.nvm"
. "/usr/local/opt/nvm/nvm.sh"

NVM commands

Now that you have NVM installed, let's see some of the most useful commands.

nvm ls

nvm ls shows all the versions.

nvm use

E.g nvm use v20.6.0

Install the new version suppose node version 20.

nvm install 20

After installing the Node version you want, you can use it by running the following command:

nvm alias default <node_version>

nvm use

After nvm use, you can check the version:

node -v

By running above command, nvm switches the Node version to the one you specified.

红颜悴 2025-01-19 16:11:37

安装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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文