We usually install the latest version of Node, but sometimes we need to use the earlier version of Node. Without the help of third-party tools, we can only uninstall the existing version and install the required version. This is obviously very troublesome. Node.js version Management allows you to switch between multiple Node versions.

1, download

Download address

Insert a picture description here

2. Install the NVM

Note: The installed must be completely uninstalled before installationnode

Unzip the. Zip package and double-click nVM-setup. exe to start the installation. Note the following two steps:

  • So here’s the SettingsnvmInstallation path of
Insert a picture description here
  • Here are the Settings usednvmThe installationnodeWhen,nodeInstallation path of
Insert a picture description here

After the installation is complete, enter NVM -v in the CMD window. If the following version number is displayed, the installation is successful

Running version 1.17..
Copy the code

3. (Optional) Modify the NVM configuration file

After the NVM installation is complete, open settings. TXT in the NVM installation directory:

root: D:\nvm
path: D:\nodejs 
arch64 
proxy: none
node_mirror: http://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
Copy the code

Root and Path are the installation paths of NVM and Node respectively. Do not touch these two. They are automatically generated during the previous installation based on the path you chose. Arch means how many bits of node are installed, proxy means to set the proxy, node_mirror means to change the mirror when NVM downloads node, here it is set to Taobao mirror. Npm_mirror is to change the NPM download dependency package mirror, is also changed to Taobao mirror.

4. Install node

  • To viewnvminstallablenodeversion

Use NVM list available

Insert a picture description here
  • useNVM Install version numberInstall the specified versionnode

NVM does not support 12.0.0. Node does not support 12.0.0 either, so it is important to check the version number before installing. I chose to install 12.18.3 here.

C:\Users\Silence>nvm install 12.183.
Downloading node.js version 12.183. (64-bit)...
Complete
Creating D:\nvm\temp

Downloading npm version 6.146.. Complete Installing npm v614.6.. Installation complete. If you want to usethis version, type

nvm use 12.183.
Copy the code

Here both Node and NPM are installed. Because I did not modify the download image, the speed is very slow. If you mind, you can modify the download image to Taobao image.

  • detectionnodeandnpmIf the following information is displayed, the installation is successful:
C:\Users\Silence>node -v
v1218.3.

C:\Users\Silence>npm -v
6.146.
Copy the code

5. Switch the Node version

After installing nodes using NVM for the first time, you must use the NVM use version number to switch to the installed version of node

C:\Users\Silence>nvm use 12.183.
Now using node v1218.3. (64-bit)
Copy the code

I didn’t switch at the beginning and found that the nodejs directory I specified was not in disk D, which appeared later after executing the switch command.

6. Configure node

  • Modify the download path of global dependent packages

I installed node on drive D, but if you use Node to install global dependency packages, it will still download the dependency packages to drive C, so I will change the following two CMD commands, respectively

C:\Users\Silence>npm  config set prefix "D:\nodejs\node_global"

C:\Users\Silence>npm  config set cache "D:\nodejs\node_cache"
Copy the code

After executing this command, I will create the node_global directory in my D:\nodejs directory. The node_cache directory is the cache directory, which will be generated after downloading dependencies using NPM

  • Viewing the Modification Result
C:\Users\Silence>npm config list
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "NPM / 6.14.6 node/v12.18.3 win32 x64"

; userconfig C:\Users\Silence\.npmrc
cache = "D:\\nodejs\\node_cache"
prefix = "D:\\nodejs\\node_global"

; node bin location = D:\nodejs\node.exe
; cwd = C:\Users\Silence
; HOME = C:\Users\Silence
; "npm config ls -l" to show all defaults.
Copy the code
  • Modifying Environment Configurations

Since I changed the download directory of the global dependency package, I need to add that directory to the environment variable, otherwise I will get an error using the global directive. Skip this step if you haven’t changed the download directory of global dependencies.

Insert a picture description here

As you can see, the environment configuration of NVM has been added, there is no need to manually add, in fact, if you look carefully, when installing NVM, the interface will also be prompted to automatically add.

7. Switch between nodes of multiple versions

To demonstrate the multi-version node switch, I repeat step 4 above and install the latest version of Node

  • View all that are currently installednodeversion
C:\Users\Silence>nvm list

    14.7. 0
  * 12.183. (Currently using 64-bit executable)
Copy the code

The * character indicates the version currently in use

  • Switch between different versionsnoe
C:\Users\Silence>nvm use 14.7. 0
Now using node v147.. 0 (64-bit)

C:\Users\Silence>nvm list

  * 14.7. 0 (Currently using 64-bit executable)
    12.183.
Copy the code

8, NVM common instructions

nvm off                     // Disable Node.js versioning (without uninstalling anything)
nvm on                      // Enable node.js version management
nvm install <version>       // Install the specified version of Node, for example, NVM install 12.18.3
nvm uninstall <version>     // Uninstall the specified version of Node, for example, NVM uninstall 12.18.3
nvm list                    // Displays all installed Node.js versions
nvm list available          // Display all available node.js versions (Windows)
nvm use <version>           // Switch to using the specified nodeJS version, such as NVM use 12.18.3
Copy the code

It is not easy to write. If you think the article is helpful to you, you can click a “like” or scan the QR code below to follow my wechat official account

My wechat official account