How to upgrade the version of node and npm

In a sense, node and npm have already become indispensable tools in current front-end development.
This article will introduce how to upgrade and specify the version of node and npm.

Check the version version of node and npm:

node -v

npm -v

Clear npm cache:

npm cache clean -f

How to upgrade npm

When only a simple upgrade is required npm, it can be handled more conveniently.

  • npm upgrade to latest version
npm install npm -g
  • npm upgrade to the specified version
npm install [email protected] -g

The purpose of upgrading npm can be achieved through the above commands, but if you want to upgrade npm synchronously by upgrading node, you need to use other methods.

How to upgrade node version

use n module

The n module is specially used to manage the version of nodejs, through which the version of node can be upgraded, but it is not suitable for the win system.

Install:

npm install n -g

View n module version:

n -V

If so -bash: n: command not found, a soft connection needs to be established:

ln -s /tools/node/bin/n /usr/local/bin/n

After connecting, there will be ncommands, and corresponding operations can be performed.

Use the n module to upgrade the node version:

n 14.17.0  ## 升级到指定版本

n latest   ## 升级到最新版本

n lts 	   ## 升级到长期支持版本

n stable   ## 升级到最新的稳定版本

Use tools such as nvm

nvmIt is a node version management tool, which can be used under the win system, and there are similar ones gnvm.

Install under the win system, download the corresponding installation package, and install it step by step. The process is omitted here.
It should be noted that the installed node must be uninstalled during installation, and if the command cannot be found when executing the command line, you need to configure the environment variable.

Introduction to common commands:

nvm ls                ## 查看已安装的所有node版本

nvm install node      ## 安装最新版本

nvm install version   ## 安装指定版本

nvm use version       ## 使用指定版本

nvm current           ## 查看当前版本

gnvm

gnvm can download and install the node version management tool under the win system, and the use of commands is similar:

gnvm install latest   ## 安装最新版本

gnvm install version  ## 安装指定版本

gnvm update latest    ## 更新最新版本

gvnm npm latest  ## 安装npm

gnvm uninstall   ## 卸载

gnvm ls
gnvm use

Guess you like

Origin blog.csdn.net/jimojianghu/article/details/127367483