Learning Center
Node.js

How to Install Node.js and NPM on Ubuntu 24.04

27 Jan 2026
JC Brian Refugia
JC Brian Refugia

The popular JavaScript runtime Node.js enables server-side programming with JavaScript. NPM, a package manager for Node.js projects, helps with dependency management. This guide will show how to install NPM and Node.js on Ubuntu 24.04. To learn how to use cloud server on Ubuntu in right way click here.

Prerequisites
Copy link

Installing Node.js and npm from the Default Ubuntu Repository
Copy link

  1. Update the package lists to ensure to have the most recent information on package versions and dependencies. Run the command below: 

sudo apt update && sudo apt upgrade -y
  1. Node.js is normally available from Ubuntu's default repository. Install it by running the following command:

sudo apt install nodejs npm  -y

Image1

Installing Node.js and npm via the NodeSource Repository
Copy link

  1. Add the NodeSource repository for Node.js: 

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash - 

7b6a7095 40cc 4db7 Acfb 32ea72359f17

  1. Use the following command to install Node.js after adding the NodeSource repository:

sudo apt install nodejs -y

Verifying the Node.js and npm Installation
Copy link

Verify the following versions of Node.js and npm to make sure they were installed correctly. Run the below command.

node -v

Image11

npm version

Image17

Installing Specific Node.js Versions with NVM 
Copy link

With the help of the robust utility Node Version Manager (NVM), devops may easily manage several Node.js versions on a single machine. This is very helpful when switching between several project needs.

  1. To install NVM, download and run the installation script from the NVM repository using the following command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

Image13

  1. After running the scripts, source the user profile and add NVM to the shell session. Add the following lines to the user's home directory (~/.bashrc, ~/.zshrc, or the corresponding shell profile script). Create it using nano editor:

nano ~/.bashrc
  1. 3. Add the following content:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Image10

  1. Run the command below so changes will take effect.

source ~/.bashrc

Image8

  1. With NVM installed, install the specific versions of Node.js. In this case, to install Node.js version 16, run the command below:

nvm install 16

Image2

  1. Switch to a specific version of Node.js that is installed, using the command below.

nvm use 16

Image19

Managing Node.js Projects
Copy link

Several essential procedures and best practices are involved in managing Node.js projects in order to ensure the effectiveness, maintainability, and scalability of the application.

This is a tutorial to help to efficiently manage your Node.js projects.

  1. Launch the terminal, navigate to the project creation path, and make a folder named after the project you are creating.

mkdir my_project

Image20

  1. Initiate the Node project by running the command npm init. Provide the required details (marked in red). All of the answers in this example will be default. The file package.json will result from this.

npm init

Image14

  1. Install any required dependencies, such as nodemon and express. The package-lock.json file and the node_modules folder will be created as a result.
npm i express nodemon

Image5

  1. To initialize git in the project, use the git init command. This will include the file .gitignore.
git init

Image6

  1. Make a file called Readme.md that will have all of the project's information.
touch Readme.md

Image9

  1. Make a file with the .env extension that will hold the project's credentials and sensitive data.
touch process.env

Image7

  1. To launch the program, create a file with the name app.js or index.js.
touch app.js

Image4

  1. Make two folders: Public (which contains resources and static files) and src (which contains controllers, models, routes, and views).
mkdir Public src

Image15

  1. Check each and every folder and file that was generated. This is how a typical structure might look like. For the NODE JS application, it is best practice to establish a project structure, divide files based on their function, and place those files in the appropriate directories. To make it simple to confirm the existence and logic of any given file or folder, unify the application's naming conventions and include business logic in the controllers folder, for instance.
ls -lrt

Image18

Best Practices for Node JS Project Structure
Copy link

  1. For production systems, set up logging and monitoring with tools like Datadog or New Relic.

  2. Plan routine maintenance activities including performance reviews, security audits, and dependency updates.

  3. Put in place a backup plan for important configurations and data.

  4. Check for security flaws in your dependencies and code on a regular basis.

Troubleshooting Common Issues
Copy link

There are some frequent problems that a user could run into when installing npm and Node.js. These troubleshooting instructions should help you to address the majority of typical problems that arise when installing npm and Node.js. The steps for troubleshooting these issues are listed below:

  1. When attempting to install Node.js or npm globally (i.e., using sudo), users get permission-related issues that prevent them from finishing the installation process.

  2. After installing nvm, the command is not recognized. The error nvm Command Not Found will be encountered. Make sure that the shell's configuration file (.bashrc, .bash_profile, .zshrc, etc.) has nvm sourced, and then the command source ~/.bashrc has been use to reload it.

  3. The npm version is out of date or does not correspond with the Node.js version after installing Node.js. Use nvm install <version> to install a particular Node.js version, which will include the matching npm version, and manually update npm by running npm install -g npm

Conclusion
Copy link

In conclusion, an important initial step in creating new web applications and utilizing server-side JavaScript is installing Node.js and npm. Although installing software is usually simple, there are a few frequent problems that can arise, such as permissions conflicts, environment setup problems, or version mismatches. One can successfully overcome these problems by configuring npm to be compatible with your network environment, modifying system settings for global installations, and managing Node.js versions with tools like nvm.

Do not forget to update npm and Node.js frequently to take advantage of the newest features and security updates. It will have a strong base for developing and implementing Node.js-powered, scalable applications with correct setup and troubleshooting.

Frequently Asked Questions (FAQ)
Copy link

How do I install Node.js on Ubuntu? 
Copy link

You have two main options:

  1. For Stability (System Default): Run sudo apt update followed by sudo apt install nodejs npm. This installs the version maintained by Ubuntu (usually an LTS release).

  2. For Developers (Recommended): Use NVM (Node Version Manager). It allows you to install multiple versions and switch between them easily without sudo.

How to check if Node.js is installed in Ubuntu? 
Copy link

Open your terminal and run the version command: node -v If installed, it will output the version number (e.g., v18.19.0). To check NPM, run npm -v.

What is npm i and npm install? 
Copy link

They are the same command. npm i is simply a standard alias (shorthand) for npm install. Both commands read your package.json file and install the listed dependencies into the node_modules folder.

How do I update Node.js on Ubuntu?
Copy link

  • If using Apt: Run sudo apt update && sudo apt upgrade.

  • If using NVM: simply install the new version (e.g., nvm install 20) and switch to it (nvm use 20).

Where does Node.js install on Linux?
Copy link

  • Apt installation: Binary is located at /usr/bin/node.

  • NVM installation: Binary is located inside your home directory, typically ~/.nvm/versions/node/v[version]/bin/node.

How do I fix "EACCES: permission denied" errors when installing global packages?
Copy link

 This happens if you installed Node via apt and try to install a global package without sudo.

  • Fix 1 (Best): Use NVM, which manages permissions for you.

  • Fix 2: Change the location of your global npm directory to a folder you own (like ~/.npm-global).