You should have a non-root user account with sudo privileges set up on your system. You can do so by running the following command:

$ sudo usermod -aG sudo [YOUR_USERNAME]

Replace "[YOUR_USERNAME]" with the user you are currently logged in as. This command adds your user to the sudo group.

Installing NVM

An alternative to installing Node.js with apt is to use a tool called nvm, which stands for “Node.js Version Manager”. You can install multiple self-contained versions of Node.js without affecting the entire system.

Use curl to download the nvm installation script from theproject’s GitHub page:

$ curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh -o install_nvm.sh

Run the script with bash:

$ bash install_nvm.sh

Source the ~/.profile file so that your current session knows about the changes:

$ source ~/.profile

To check which version of NVM is installed, type:

$ nvm --version

The output will be something like:

0.35.3

It is recommended that you install either LTS or current version of Node. The latest LTS version is v12.18.3. You can install that by typing:

$ nvm install 12.18.3

You can tell nvm to use the version you just downloaded by typing:

$ nvm use 12.18.3

To check if Node is installed, type:

$ node -v 

The output will be something like this:

v12.18.3