How to properly upgrade node using nvm

2019-03-07 09:48发布

Is it possible to upgrade node right in place, instead of manually installing the latest stable version?

I have installed node.js version 5.0 with 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...).

4条回答
等我变得足够好
2楼-- · 2019-03-07 10:15

TWO Simple Solutions:

To install the latest version of node and reinstall the old version packages just run the following command.

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.

nvm install lts/* --reinstall-packages-from=node

Here's a GIF to support this answer. nvm

查看更多
爷的心禁止访问
3楼-- · 2019-03-07 10:21

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

Alternatively, try:

nvm install stable
查看更多
放我归山
4楼-- · 2019-03-07 10:24

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

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.

查看更多
地球回转人心会变
5楼-- · 2019-03-07 10:25

if you have 4.2 and want to install 5.0.0 then

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.

source: sitepoint

查看更多
登录 后发表回答