By Using NVM or Node Version Manager
The NVM is also an easy to use and installer for the node and it offers the flexibility for us to easily switch between different versions of node, let’s understand step by step how to install node.js and npm using NVM:
Step 1: Install NVM
First, we will have to curl and install NVM, for this run the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
This will give us the following output:
Step 2: Check if NVM is Installed
To check whether the NVM is installed or not we will run the following command:
command -v nvm
This will give us the following output:
Step 3: List Versions and Select
Now you simply need to list all the versions available and choose the one of your requirement, for this run the following command:
nvm list-remote
This will give us the following output:
After this, you will have to enter the following command to install the version of your choice:
nvm install <version-name>
This will give us the following output:
Step 4: Switch to the Installed Version of Node.js
Now simply run the following command and mention the version that you want to switch to:
nvm use <your-installed-version-number>
This will give the following output:
Finally, you have successfully installed and switched to the version of your choice using NVM.
How to Install Node.js and npm on Ubuntu?
As you may be aware already, npm and node.js are very powerful web development tools that are used for full-stack development purposes. It is straightforward if you ever want to install npm or node.js in the Windows operating system. In this article, we will cover some effective methods that you can use to install npm as well as node.js in your required distribution.