Installation of npm and Nodejs with nvm and switching between versions.

NVM (Node Version Manager) is a version manager for npm with which you can easily install, uninstall, and switch between versions without the problems involved in all this. In other posts we have specifically seen how to install the latest version of node and npm for some platforms without using nvm.
- Install the latest version of npm and Nodejs in Ubuntu
- Install the latest version of npm and Nodejs in GNU/Linux Debian
- Install the latest version of npm and Nodejs in Arch Linux
However, I highly recommend installing npm and Nodejs with nvm as you can easily switch between versions when required and it is extremely simple.
Installation of NVM
Installing NVM is relatively easy, you just need to run the following command to install the current version which is 0.39.1. To check the current version you can visit the NVM repo directly.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Node Installation
To install the latest version of node you can run the following commands.
nvm install node
nvm use node
If you want to install a previous version such as version 14, you must indicate it like this.
nvm install 14
nvm use 14
You can verify which versions of node and npm were installed with the following commands.
# node -v
v14.18.2
# npm -v
6.14.15
Switching Node Versions
To switch Node versions, you must use use.
nvm use 16
If the version to use is not installed, you must install it first.
nvm install 16
nvm use 16