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
- Install Node.js from NodeSource
- Check Node.js and npm versions
- Common issues
- 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
Related Posts
- AWS Lambda Function with Response Streaming using Node.js
- Build a Chrome Extension with Svelte
- Focus a Dynamic Input Field in Svelte
- Svelte Tutorial - A Thorough Introduction to SvelteJs
- How to Deploy a SvelteKit App to Firebase
- Install Bootstrap in SvelteKit
- How to fix Nginx 403 Forbidden Error
- Linked List Implementation in C++ - A Step by Step Guide
- Queue Implementation in C++ - A Step by Step Guide
- C++ Interview Questions and Answers