NVM for NodeJS multi-version management

background

Sometimes the development environment requires multiple versions of NodeJS. At this time, NVM can be used for management.

installation steps

  1. Download NVM,
    search for NVM in Github, and find the NVM project

insert image description here
2. Find version 1.1.7 and click to download
https://github.com/coreybutler/nvm-windows/releases/tag/1.1.7
Note, 1.1.9 has a bug of garbled characters, I recommend using 1.1.7
insert image description here

3. Install after downloading [window machine as an example]

4. Open cmd and execute commands to install different versions of Node

C:\Users\35490>nvm version
1.1.9
C:\Users\35490>nvm list
No installations recognized.
C:\Users\35490>nvm install v16.10.0
Downloading node.js version 16.10.0 (64-bit)...
Extracting...
Complete
Installation complete. If you want to use this version, type
nvm use 16.10.0
C:\Users\35490>nvm list
    16.10.0
C:\Users\35490>node -v
'node' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

5. Switch or use version version

nvm use 16.10.0

Set up local Node and NPM mirrors

After installing nvm, if you want to switch the image of node and npm dependent packages to taobao, you need to modify the setting file in the nvm installation directory, and then add the following two lines

node_mirror: http://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

The question is how to find the nvm directory? Execute the following command:

C:\Windows\system32>where nvm
C:\Users\35490\AppData\Roaming\nvm\nvm.exe

insert image description here

Garbled solution

If some garbled characters appear when executing certain nvm commands, such as the following, how to solve it?

C:\Users\35490>nvm use 14.20.1
exit status 5: �ܾ����ʡ�
exit status 1: ���ļ��Ѵ���ʱ���޷��������ļ���

insert image description here
The solution is to open cmd with admin administrator privileges

List of all nvm commands

The commands supported by nvm are as follows:

C:\Users\35490>nvm

Running version 1.1.9.

Usage:

  nvm arch                     : Show if node is running in 32 or 64 bit mode.
  nvm current                  : Display active version.
  nvm install <version> [arch] : The version can be a specific version, "latest" for the latest current version, or "lts" for the
                                 most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults
                                 to system arch). Set [arch] to "all" to install 32 AND 64 bit versions.
                                 Add --insecure to the end of this command to bypass SSL validation of the remote download server.
  nvm list [available]         : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls.
  nvm on                       : Enable node.js version management.
  nvm off                      : Disable node.js version management.
  nvm proxy [url]              : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.
                                 Set [url] to "none" to remove the proxy.
  nvm node_mirror [url]        : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.
  nvm npm_mirror [url]         : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.
  nvm uninstall <version>      : The version must be a specific version.
  nvm use [version] [arch]     : Switch to use the specified version. Optionally use "latest", "lts", or "newest".
                                 "newest" is the latest installed version. Optionally specify 32/64bit architecture.
                                 nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode.
  nvm root [path]              : Set the directory where nvm should store different versions of node.js.
                                 If <path> is not set, the current root will be displayed.
  nvm version                  : Displays the current running version of nvm for Windows. Aliased as v.

Summarize

It is very easy to install different versions of NodeJS and switch through nvm, which is very convenient!

Guess you like

Origin blog.csdn.net/chancein007/article/details/127606830