node.js 如何使用 NVM 设置默认节点版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47190861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:34:18  来源:igfitidea点击:

How can the default node version be set using NVM?

node.jsversionnvm

提问by Pablo Ezequiel

I have installed nvm (ubuntu with zsh shell) with two node version: v6.11.5 and v9.0.0 and the default version in nvm is the v9.0.0

我已经安装了具有两个节点版本的 nvm(带有 zsh shell 的 ubuntu):v6.11.5 和 v9.0.0,nvm 中的默认版本是 v9.0.0

Every time I need to change the node version

每次我需要更改节点版本时

$ nvm list
         v6.11.5
->       v9.0.0
         system
default -> node (-> v9.0.0)
node -> stable (-> v9.0.0) (default)
stable -> 9.0 (-> v9.0.0) (default)


$ nvm v6

How could I change the nvm version default to define v6.11.5?

如何更改 nvm 版本默认值以定义 v6.11.5?

回答by LJHarb

(nvm maintainer here)

(这里是 nvm 维护者)

nvm alias default 6.11.5if you want it pegged to that specific version.

nvm alias default 6.11.5如果您希望它与该特定版本挂钩。

You can also do nvm alias default 6.

你也可以这样做nvm alias default 6

Either way, you'll want to upgrade to the latest version of nvm(v0.33.11 as of this writing)

无论哪种方式,您都需要升级到最新版本nvm(截至撰写本文时为 v0.33.11)

回答by Dipesh Yadav

Lets say to want to make default version as 10.19.0.

假设要将默认版本设为 10.19.0。

nvm alias default v10.19.0

But it will give following error

但它会给出以下错误

! WARNING: Version 'v10.19.0' does not exist.
default -> v10.19.0 (-> N/A)

In That case you need to run two commands in the following order

在这种情况下,您需要按以下顺序运行两个命令

# Install the version that you would like 
nvm install 10.19.0

# Set 10.19.0 (or another version) as default
nvm alias default 10.19.0