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.
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
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.
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.
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.
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.