Skip to content
Follow
Ubuntu Linux

Install Node.js and npm on Ubuntu: A Step-by-Step Guide

Richard
Written by
Richard
Sep 26, 2021 Updated Jul 14, 2026 5 min read
How to Install VMware Workstation Player on Ubuntu Linux
How to Install VMware Workstation Player on Ubuntu Linux

Node.js and npm install on Ubuntu to help you run JavaScript code for web applications. Node.js is a program that lets you use JavaScript outside of your web browser. npm is a tool that comes with Node.js and helps you find and use pre-written code for your projects.

You can install Node.js and npm on Ubuntu using either the official NodeSource repositories or Ubuntu’s own software sources. This guide focuses on installing a recent stable version, typically v20.x or higher.

⚡ Quick Answer

Install Node.js and npm from Ubuntu’s default repositories by running sudo apt update followed by sudo apt install nodejs npm. Alternatively, use Snap with sudo snap install node –classic or add the NodeSource repository and then run sudo apt install nodejs. Check the installation with node –version and npm –version.

How to install Node.js from Ubuntu repositories

Node.js and npm can be installed on Ubuntu directly from official software sources using simple commands. This approach provides a stable version of Node.js for most projects and is a clear way to start using Node.js on your Ubuntu system.

⚠️Warning
To install Node.js and npm on Ubuntu, run two commands. The first command updates the list of available software packages. The second command then installs both Node.js, a JavaScript runtime, and npm, a package manager, ensuring you have version 18.10.0 or later for modern development.
🐧Bash / Shell
sudo apt update
sudo apt install nodejs npm

Running that command installs several Node.js and npm packages. These include tools needed to compile and install native add-ons from npm.

Once the installation is complete, run the commands below to check the installed version.

💻Code
nodejs --version

That should output a similar line as shown below:

💻Code
v10.19.0
⚠️Warning
As you can see, the latest version in Ubuntu is v10.19.0. However, newer v11, v12, v13, and v14 have also been released.

How to Install Node.js and npm from Snap

Installing Node.js and npm using Snap packages offers a method that bundles all necessary components. Snaps are self-contained software packages. They update automatically and can revert to a prior version if a new update causes problems, making them a reliable choice for your development environment.

Snaps are software packages that bundle all their necessary components. This design allows a single Snap to run on many Linux systems without modification. Snaps update themselves automatically and can revert to a working version if a new update causes issues.

To install via Snap, run the commands below to install Snap.

🐧Bash / Shell
sudo apt update
sudo apt install snapd

Once Snap is installed, run the commands below to get Node.js and npm installed via Snap. Choose the correct Node.js versions you want to install in Ubuntu.

For the Latest release (version 14),

🐧Bash / Shell
sudo snap install node --channel=14/stable --classic

For version 13, run this:

🐧Bash / Shell
sudo snap install node --channel=13/stable --classic

For the LTS (version 10)

🐧Bash / Shell
sudo snap install node --channel=10/stable --classic

How to Install Node.js and npm from NodeSource

NodeSource offers a reliable method to install the latest Node.js versions on your Ubuntu system. This approach is perfect if you need the newest features and updates, ensuring your development tools are always current and giving you access to specific versions for your projects.

You can use the NodeSource repository to install a specific version of Node.js. Currently, the repository lists Node.js versions 14, 12, 11, 10, and 8. Note that version 14 is listed twice; typically, this refers to different release lines within the same major version.

To install Node.js from NodeSource, run the commands below to add the repository for your desired version.

Then for the Latest release (version 14), add this PPA.

💻Code
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

For (version 12), run the commands below:

💻Code
curl -sL https://deb.nodesource.com/setup_12.x | bash -

To install the LTS release (version 10), use this PPA

💻Code
curl -sL https://deb.nodesource.com/setup_10.x | bash -

After adding the repository, you can now install the Node.js version you selected. If you add multiple repositories, your system will install the newest version of Node.js, not necessarily the Long Term Support (LTS) version.

Install Node.js and npm

After adding the NodeSource repositories, you can install Node.js and npm using the `sudo apt install nodejs` command. This single command installs both programs. You can then check the installed versions to confirm Node.js version 18.17.0 and npm version 9.6.7 are ready for use.

🐧Bash / Shell
sudo apt install nodejs

After installing, both Node.js and npm modules should be ready to use.

You can use the commands below to view the installed version number.

💻Code
node --version
npm --version

The commands will list the currently installed version:

💻Code
v14.0.0
6.14.4

To test whether the web server is properly installed, run the commands below to create a test file called http_server.js in your home folder.

Command Prompt
cd ~/
nano http_server.js

Then copy and paste the content below into the file and save it.

🟨JavaScript
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello Worldn');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

After that, save the file and run the commands below to start the server.

💻Code
node http_server.js

You should see an output that reads:

The server running at http://127.0.0.1:3000/

Now open your browser and browse to the server hostname or IP address followed by port 3000. You should see a default page with Hello World.

💻Code
http://localhost:3000
Node.js ubuntu install
nodejs ubuntu install

That should do it!

Conclusion:

This installation guide provided steps to install Node.js and npm on Ubuntu Linux. If you encounter any errors or have additional information to share, feel free to use the comment form below.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04
Advanced Windows 11 Guide For Developers
Windows Advanced Windows 11 Guide For Developers
How to Change Default Distro in Windows Subsystem for Linux
Windows How to Change Default Distro in Windows Subsystem for Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *