By Vivek - May 2, 2024

How to Install Node.js and NPM on Ubuntu

Node.js and npm are required for most JavaScript, Svelte, SvelteKit, and tooling workflows. This guide installs Node.js on Ubuntu using the NodeSource packages, then verifies both node and npm from the terminal.

Table of Contents

  1. Install Node.js from NodeSource
  2. Check Node.js and npm versions
  3. Common issues
  4. Related JavaScript guides

Installing NodeJs from node source

Node.js package is available in the LTS and current release. According to your needs, you can select which version you would like to install. We’ll install Nodejs 22 which is the current version.

sudo apt-get install curl

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

sudo apt-get install nodejs

Check NodeJs and NPM Version:

node -v
# v22.0.0

npm -v
# 10.5.1

Common Issues

The node command is not found

Close and reopen the terminal, then run node -v again. If it still fails, repeat the install step and check the command output for apt errors.

Permission errors with global packages

Avoid running every npm command with sudo. If global installs fail, consider using a Node version manager for local development or configure npm’s global package directory for your user account.

The Node.js version is too old

Some SvelteKit and Vite projects require a recent Node.js version. Check the project’s package.json engines field or framework documentation before installing dependencies.

Related JavaScript Guides