Debian doesn’t use sudo. Make sure to run everything as root user with su.

Step 1 - Installing Prerequisites

Let’s first install curl.

apt install curl -y

Step 2 - Install NVM

We are pulling nvm from the git repository.

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

To apply the changes, either log out and back in or source your ~/.profile.

source ~/.profile

Step 3 - Installing Node using NVM

Installing the latest NodeJS:

nvm install node

You can choose the version of Node that you would like. Here is the list of all available versions:

nvm ls
nvm install your-node-version

Step 4 - Optionals / Cool Features

It is surprisingly easy to switch Node versions on the fly!

You can run individual scripts as the desired version:

nvm exec desired-node-version index.js

To set a Node version:

nvm use desired-node-version

To set a new default version:

nvm alias default desired-node-version