What is NVM, and how to use it?
The definition, installation, and usage of NVM are explained.
What is NVM?
Firstly, we can define NVM as “Node Version Manager.” Typically, you can download only one version of Node.js, and if you want to use another version, you have to replace the old version with the new one. It is not much of a problem if you are not continuously developing a program; however, if you are, you have probably encountered the problem of continually updating or changing the Node.js version. But there is a way to make it easy to manage and use more than one Node.js version simultaneously with NVM, saving you time.
NVM Installation and Usage
As for how NVM works, we first need to download the NVM installation file from GitHub and execute it. There are three methods of installation. In the first two, we automatically install NVM via Command Prompt, and in the third method, we download and set up NVM manually by downloading the source files from GitHub.
cURL:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Wget:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Manual installation:
https://github.com/nvm-sh/nvm/releases
You can download the .zip or .tar.gz file in Latest Version > Assets using the link above.
After extracting the compressed file, you can complete the installation by executing the installation file.
After completing the installation, to use NVM, you can execute the commands given in the next section by opening it as administrator. NOTE: If you don’t open the command prompt as administrator, you might encounter the “access is denied” error like the following.
Commands
- To check the current default version of Nodejs, you can use this command:
nvm version
=> 0.39.1
- To install any version of Node:
nvm install 17.0.1
- To check all the installed versions of Node: (* shows the current default version)
nvm ls
* 17.0.1 (Currently using 64-bit executable)
16.14.0
14.16.1
or
nvm list
* 17.0.1 (Currently using 64-bit executable)
16.14.0
14.16.1
- To set a version of Node as default:
nvm use 16.14.0
- To launch a file with a specific version without setting it default:
nvm run 16.14.0 index.js
- To uninstall a version of Node:
nvm uninstall 16.14.0
That’s all.
Have a good day of coding!