domo

domo

Switching Node versions on Mac.

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.

image

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

image

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
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.