How to use node version manager (NVM) on ubuntu 20.04
Node Version Manager (NVM) is a tool used to manage multiple active Node.js versions. The Node.js platform, Node.js community of tools, and Node.js libraries are fast-moving targets — what might work under one Node.js version is not guaranteed to work for another version of Node.js.
Using NVM, you can easily switch between multiple versions of Node.js right from the command line and set up aliases to switch between different downloaded versions with ease.
Setting Up NVM
Run the NVM installer using the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
This will install the nvm
script to your user account. To use it, you must first source your .bashrc
file:
$ source ~/.bashrc
We can quickly verify that NVM is now installed and working properly with the following command:
nvm --version
Using NVM
1.Install Node.js
nvm install <SPECIFIC_NODE_VERSION>
2.Install Node.js latest version
nvm install node
3. To use any specific version of Node.js for your code
nvm use <SPECIFIC_NODE_VERSION>
4. To list installed Node.js versions locally on your machine, use
nvm ls
5. List all available LTS versions of Node.js.
nvm ls-remote
Switching between Node.js versions
nvm use <SPECIFIC_NODE_VERSION>
To switch through installed versions nvm provides the nvm use
command. This works similarly to the install command. So, you need to follow this by a version number or an alias.
To check the current version
nvm current
To set a specific node version as default
nvm alias default <SPECIFIC_NODE_VERSION>
It will set a specific node version permanently in all instances
To uninstall specific node version
nvm uninstall <SPECIFIC_NODE_VERSION>
NVM is simple, and it makes development in whatever version of Node.js that’s required, so much simpler as well. I hope you’ll take advantage of it.