node.js 如何使用 nvm 正确升级节点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34810526/
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
How to properly upgrade node using nvm
提问by Boris Burkov
Is it possible to upgrade noderight in place, instead of manually installing the latest stable version?
是否可以node就地升级,而不是手动安装最新的稳定版本?
I have installed node.jsversion 5.0with nvm, but now I want to update it to 5.4. I'm trying to avoid having to manually reinstall all of my global packages (e.g.by running npm install -g grunt-cli bower yo yoman-angular-generator blabla blablablabla...).
我已经安装了Node.js的版本5.0有nvm,但现在我想将其更新到5.4。我试图避免手动重新安装我所有的全局包(例如通过运行npm install -g grunt-cli bower yo yoman-angular-generator blabla blablablabla...)。
回答by gabrielperales
This may work:
这可能有效:
nvm install NEW_VERSION --reinstall-packages-from=OLD_VERSION
For example:
例如:
nvm install 6.7 --reinstall-packages-from=6.4
then, if you want, you can delete your previous version with:
然后,如果需要,您可以使用以下命令删除以前的版本:
nvm uninstall OLD_VERSION
Where, in your case, NEW_VERSION = 5.4 OLD_VERSION = 5.0
在你的情况下,NEW_VERSION = 5.4 OLD_VERSION = 5.0
Alternatively, try:
或者,尝试:
nvm install stable
回答by Elad
You can more simply run one of the following commands:
Latest version: nvm install node --reinstall-packages-from=node
Stable (LTS) version: nvm install lts/* --reinstall-packages-from=node
您可以更简单地运行以下命令之一:
最新版本:nvm install node --reinstall-packages-from=node
稳定(LTS)版本: nvm install lts/* --reinstall-packages-from=node
This will install the appropriate version and reinstall all packages from the currently used node version. This saves you from manually handling the specific versions.
这将安装适当的版本并从当前使用的节点版本重新安装所有软件包。这使您无需手动处理特定版本。
Edit - added command for installing LTS version according to @m4js7er comment.
编辑 - 根据@m4js7er 评论添加了用于安装 LTS 版本的命令。
回答by Ahmad Awais
? TWOSimple Solutions:
? 两个简单的解决方案:
To install the latest version of node and reinstall the old version packages just run the following command.
要安装最新版本的 node 并重新安装旧版本的软件包,只需运行以下命令。
nvm install node --reinstall-packages-from=node
To install the latest lts(long term support) version of node and reinstall the old version packages just run the following command.
要安装最新lts(长期支持)版本的节点并重新安装旧版本软件包,只需运行以下命令。
nvm install --lts /* --reinstall-packages-from=node
回答by Tanveer Hossain Jony
if you have 4.2 and want to install 5.0.0 then
如果你有 4.2 并且想要安装 5.0.0 那么
nvm install v5.0.0 --reinstall-packages-from=4.2
the answer of gabrielperales is right except that he missed the "=" sign at the end. if you don't put the "=" sign then new node version will be installed but the packages won't be installed.
gabrielperales 的答案是正确的,只是他错过了最后的“=”符号。如果您不放置“=”符号,则将安装新的节点版本,但不会安装软件包。
source: sitepoint
来源:sitepoint
回答by Serkan
Node.JS to install a new version.
Node.JS 安装新版本。
Step 1 : NVM Install
第 1 步:NVM 安装
npm i -g nvm
npm i -g nvm
Step 2 : NODE Newest version install
第 2 步:NODE 最新版本安装
nvm install *.*.*(NodeVersion)
nvm install *.*.*(NodeVersion)
Step 3 : Selected Node Version
第 3 步:选择节点版本
nvm use *.*.*(NodeVersion)
nvm use *.*.*(NodeVersion)
Finish
结束
回答by MrSegFaulty
Bash alias for updating current active version:
用于更新当前活动版本的 Bash 别名:
alias nodeupdate='nvm install $(nvm current | sed -rn "s/v([[:digit:]]+).*//p") --reinstall-packages-from=$(nvm current)'
The part sed -rn "s/v([[:digit:]]+).*/\1/p"transforms output from nvm currentso that only a major version of node is returned, i.e.: v13.5.0-> 13.
该部分sed -rn "s/v([[:digit:]]+).*/\1/p"转换输出,nvm current以便仅返回节点的主要版本,即:v13.5.0-> 13。


