Ubuntu provides Node.js packages in it's default apt repository, but it's normally not the most up-to-date. If you require the latest version of Node.js on Ubuntu, you'll have to install them from NodeSource's PPA.

If you require Ubuntu's officially supported version of Node.js, you can install the one provided in its default apt repository. Related: How to install Node.js on Ubuntu or Debian

Steps to install latest Node.js on Ubuntu or Debian:

  1. Open the terminal application.
  2. Install curl if not already installed.

    $ sudo apt update && sudo apt install --assume-yes curl

  3. Add PPA for specific Node.js version via NodeSource's official PPA setup script.

    $ curl --silent --location https://deb.nodesource.com/setup_10.x  | sudo bash -

    Replace 10.x with 12.x, 11.x or 9.x, depending on your actual required version

  4. Install latest Node.js from the PPA.

    $ sudo apt install --assume-yes nodejs 

    npm is automatically installed as dependency and does not require separate installation.

  5. Check installed nodejs and npm version.

    $ nodejs -v v10.9.0 $ npm -v 6.2.0