Enable the NodeSource repository by running the following command in your terminal:

curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -


The current LTS version of Node.js is version 10.x, Dubnium. If you want to install Node.js version 8.x just change setup_10.x with setup_8.x

Once the repository is enabled, install Node.js and npm by typing:

sudo apt install nodejs

To verify the installation, run the following command which will print the Node.js version:

node --version