How to install Node.js on Ubuntu

Node.js lets Ubuntu systems run JavaScript services, command-line tools, and build scripts without a browser. Installing the distro package keeps the runtime under normal APT maintenance for hosts that use operating-system packages as their update source.

Ubuntu publishes the runtime as the nodejs package, while the package manager command is installed separately as npm. The installed runtime command is node, so verification should check node –version rather than the package name.

The repository version follows the Ubuntu release rather than the latest upstream Node.js release. Use the distro package when the project accepts that release line, and use a version-specific source when a project requires a newer upstream LTS or Current line.

Steps to install Node.js from Ubuntu repositories:

  1. Open a terminal with sudo privileges.
  2. Refresh the package index.
    $ sudo apt update
  3. Install Node.js and npm from the Ubuntu repositories.
    $ sudo apt install --assume-yes nodejs npm
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Solving dependencies...
    Installing:
      nodejs  npm
    ##### snipped #####
    Setting up nodejs (22.22.1+dfsg+~cs22.19.15-1ubuntu1) ...
    ##### snipped #####
    Setting up npm (9.2.0~ds3-1) ...

    The exact package versions depend on the Ubuntu release and update pocket. On Ubuntu 26.04, expect a Node.js 22 package and a separate npm 9 package.

  4. Confirm the installed Node.js runtime.
    $ node --version
    v22.22.1

    The package is named nodejs, but the runtime command is node.

  5. Confirm the installed npm command.
    $ npm --version
    9.2.0
  6. Run a short Node.js smoke test.
    $ node --eval "console.log('Node.js is working')"
    Node.js is working