Home > Article > Web Front-end > How to use nvm after installing nodejs
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
Install the specified version of Node.js. For example:
nvm install 14.15.4
Switch to use the specified version of Node.js. For example:
nvm use 14.15.4
List all installed Node.js versions. For example:
nvm ls
Lists all Node.js versions available for installation. For example:
nvm ls-remote
Set the Node.js version used by default. For example:
nvm default 14.15.4
2. Usage example
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.
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.
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.
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!