How to manage multiple nodejs versions via nvm

        With more and more front-end projects, the version of nodejs used by different projects may be different, resulting in the need to replace different nodejs versions when switching between different projects, which is very troublesome. This time, it is recommended to use nvm for unified management of multiple nodejs versions.

1. Download of nvm

       The full name of nvm is Node Version Manager, which is the Node version manager. According to your own needs, enter the official website nvm documentation manual - nvm is a nodejs version management tool - download the corresponding version from the nvm Chinese website. This article takes the Windows version as an example.

 2. Installation of nvm

        If you downloaded the Windows version, just execute the corresponding exe installation files and install them sequentially.

nvm install

3. Install nodejs version through nvm

       You can view the downloadable nodejs version by executing the nvm list available command.

nvm list available

nvm list available

         The specified version of nodejs can be installed through the nvm install version number command.

nvm install 8.12.0

nvm install

 4. View the installed nodejs version

        Use the nvm list or nvm ls command to view the installed nodejs version of the machine.

nvm list

nvm list

 5. Switch nodejs version

        Use the specified version of nodejs through nvm use version number.

nvm use 8.12.0

nvm use

6. Common commands of nvm        

  • nvm arch: Shows whether node is running on 32-bit or 64-bit.
  • nvm install <version> [arch] : Install node, version is a specific version or the latest stable version latest. The optional parameter arch specifies whether to install the 32-bit or 64-bit version, and the default is the system bit. --insecure can be added to bypass SSL for remote servers.
  • nvm list [available] : Display the installed list. The optional parameter available displays all versions that can be installed. list can be simplified to ls.
  • nvm on : Enable node.js version management.
  • nvm off : Turn off node.js version management.
  • nvm proxy [url] : Set download proxy. Without the optional parameter url, the current proxy is displayed. Setting url to none removes the proxy.
  • nvm node_mirror [url] : Set node mirroring. The default is https://nodejs.org/dist/. If no url is specified, the default url will be used. After setting, you can go to the settings.txt file in the installation directory to view it, or you can directly operate in this file.
  • nvm npm_mirror [url] : Set up npm mirroring. https://github.com/npm/cli/archive/. If no url is specified, the default url will be used. After setting, you can go to the settings.txt file in the installation directory to view it, or you can directly operate in this file.
  • nvm uninstall <version> : Uninstall the specified version node.
  • nvm use [version] [arch] : Use the specified version node. 32/64 bits can be specified.
  • nvm root [path] : Set the directory where different versions of node are stored. If not set, the current directory is used by default.
  • nvm version : Display nvm version. version can be simplified to v.

7. Use plug-ins to automatically switch nodejs versions in vscode

7.1. Install the VSCode plug-invsc-nvm

picture

 7.2 Create a file in the root directory of the project .nvmrc, and the content of the file is the version number

// .nvmrc
v8.12.0

After completing the configuration, close VSCode and reopen it, you can see that the terminal is automatically opened, and the nvm use command is executed to realize the automatic switching of the NodeJS version.


New Era Migrant Workers

Guess you like

Origin blog.csdn.net/sg_knight/article/details/131807425