We often encounter different projects that require different versions of Node in our daily use of Node. However, developers usually only have one computer, so we need a management tool to help developers switch Node versions. "n" is such a module, it is a module of Node, and its author is the author of Express.
1. Preparation#
Since "n" is a module of Node, we need to have a usable Node environment before installing "n". How to install the Node environment will not be described here.
Enter the following command in the command line:
Check the Node version
$ node -v
Check the npm version
$ npm -v
As shown in the figure, if there is a result, it means that the computer already has a Node environment.
2. Installation#
Enter the following command in the command line:
Use npm to globally install "n" (Since it needs to write files, sudo is used to elevate the operation, execute the command with administrator privileges)
$ sudo npm i -g n
After the progress bar is completed, check if the installation is complete
$ n -V
3. Installation and switching of Node versions#
List all Node versions
$ n ls
Install a specific version
$ n xx.xx.x (xx.xx.x is the version number to be installed)
Install the latest version
$ n latest
Install the latest stable version
$ n stable
Switch Node version (After entering the command, use the up and down arrow keys to select and confirm)
$ n
Remove a specific version
$ n rm xx.xx.x
Use a specific version to run a script
$ n use xx.xx.x a.js