How To

How to Install Node.js and npm on Ubuntu

If you want to build JavaScript applications on Linux, learning how to Install Node.js Ubuntu systems properly is essential. Node.js allows developers to run JavaScript outside the browser, while npm helps manage packages and project dependencies efficiently.

Ubuntu users can install Node.js using several methods depending on their workflow. Some prefer Ubuntu’s built-in packages for simplicity, while developers often use NodeSource or nvm for newer releases and version management.

Install Node.js Ubuntu Using APT

The easiest way to install Node.js on Ubuntu is through the default APT repositories. This method works well for stable environments and basic development tasks.

First, update your package lists:

sudo apt update

Then install Node.js and npm:

sudo apt install nodejs npm

After installation, verify both tools:

node -vnpm -v

Ubuntu’s repositories usually provide a stable but older release. While this approach is convenient, it may not include the latest LTS version required for modern frameworks.

To compile native npm packages, install development tools as well:

sudo apt install build-essential

Install Node.js Ubuntu with NodeSource

For users who need newer Node.js versions, NodeSource provides an official repository with updated releases.

Start by installing required dependencies:

sudo apt install ca-certificates curl gnupg

Next, import the NodeSource signing key:

sudo mkdir -p /etc/apt/keyringscurl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

Add the repository:

NODE_MAJOR=24echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

Finally, install Node.js:

sudo apt updatesudo apt install nodejs

This method installs both Node.js and npm together.

Install Node.js Ubuntu with nvm

Developers who work on multiple projects often prefer nvm, also known as Node Version Manager. It allows easy switching between different Node.js versions without affecting the entire system.

Install nvm using:

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

Reload your terminal and verify installation:

nvm -v

Install the latest LTS version:

nvm install --lts

You can also install older versions:

nvm install 22nvm install 20

Switch between versions anytime:

nvm use 22

This flexibility makes nvm ideal for modern JavaScript development environments.

Common Node.js Installation Issues

Sometimes users encounter problems like node: command not found or missing npm packages. In most cases, these issues happen because the shell session was not refreshed or Node.js was installed incorrectly.

For nvm users, reopening the terminal usually resolves the issue.

Permission problems with global npm packages are another common concern. Using nvm helps avoid these conflicts because packages remain inside the user directory instead of system folders.

Conclusion

Choosing the right way to Install Node.js depends on your workflow. Ubuntu’s default repositories are simple and stable, NodeSource offers newer production-ready releases, and nvm provides the most flexibility for developers managing multiple projects.

For most developers, nvm remains the preferred choice because it makes switching between Node.js versions fast, clean, and hassle-free.

Cyber Defence

Recent Posts

How to Add APT Repositories on Ubuntu Safely

Managing software sources is an essential part of maintaining a Linux system, and understanding APT…

4 hours ago

How to Check Website for Malware and Protect Your Site

Website malware is one of the biggest threats for website owners, bloggers, businesses, and WordPress…

17 hours ago

Install Python on Ubuntu 26.04 Like a Pro

If you want to Install Python on Ubuntu systems for development, automation, or scripting, Ubuntu…

19 hours ago

PostfixAdmin Setup on Ubuntu 26.04

Managing virtual mail users manually can quickly become difficult on a busy mail server. That’s…

23 hours ago

How to Add User to Sudoers on Ubuntu Easily

Managing administrative access properly is essential for every Linux system. When you Add User Sudoers…

1 day ago

Install Google Chrome on Ubuntu in Minutes

Installing Google Chrome on Ubuntu systems is a simple process that gives users access to…

1 day ago