Home  >  Article  >  Web Front-end  >  How to use nvm after installing nodejs

How to use nvm after installing nodejs

PHPz
PHPzOriginal
2023-05-14 10:05:081060browse

NVM (Node Version Manager) is a Node.js version management tool that allows you to install and manage multiple Node.js versions on the same computer. This means you can easily switch Node.js versions between projects or use multiple versions under the same project.

After installing Node.js through NVM, how to use it? Below I will introduce to you the common commands and usage of NVM.

1. NVM command

  1. nvm install [version]

Install the specified version of Node.js. For example:

nvm install 14.15.4
  1. nvm use [version]

Switch to use the specified version of Node.js. For example:

nvm use 14.15.4
  1. nvm ls

List all installed Node.js versions. For example:

nvm ls
  1. nvm ls-remote

Lists all Node.js versions available for installation. For example:

nvm ls-remote
  1. nvm default [version]

Set the Node.js version used by default. For example:

nvm default 14.15.4

2. Usage example

  1. Install Node.js

Use the nvm install command to install the specified version of Node.js, for example:

nvm install 14.15.4

After the installation is complete, you can use the nvm ls command to view the installed Node.js version.

  1. Switch Node.js version

Use the nvm use command to switch to the specified version of Node.js, for example:

nvm use 14.15.4

After the switch is completed, You can view the currently used Node.js version through the node -v command.

  1. Set the default Node.js version

Use the nvm default command to set the default Node.js version, for example:

nvm default 14.15.4

After the setting is completed , the default Node.js version used will be 14.15.4.

  1. Install global modules

The global module directory of Node.js installed using NVM is also separated. For example, if you install a global module yarn when using Node.js version 10.15.0, you will not be able to find and use yarn when using Node.js version 14.15.4. Because their global module directories are separate.

Therefore, if you want to use multiple versions of Node.js at the same time, it is recommended that the global modules are also installed separately. You can use the following command:

nvm use 10.15.0

Install the global module:

npm install -g [module name]

After the installation is completed, after switching to other versions of Node.js, there is no need to reinstall the global module and you can use it directly. For example, now switch to Node.js 14.15.4 version:

nvm use 14.15.4

Use global module:

[module name] [params]

Summary

NVM is a very practical Node.js version management Tools can easily install and manage multiple Node.js versions on the same computer, helping us better switch between using different versions of Node.js. Proficiency in using NVM is very helpful for daily development work.

The above is the detailed content of How to use nvm after installing nodejs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn