Introduction
Node.js is a powerful, open-source JavaScript runtime environment for building faster and scalable network applications. Node.js allows developers to run JavaScript on the server-side to create high-performing web servers, APIs, real-time applications, and more. NPM is the default package manager for Node.js for managing dependencies, installing libraries, and sharing code efficiently.
This guide shows you how to install Node.js and NPM on Ubuntu 24.04 so that you create web-based applications faster.
Prerequisites
Before you begin:
- Deploy a Digital Ocean VPS server running Ubuntu 24.04.
- Create a non-root
sudo
user. See our guide on How to create a non-root sudo user on Ubuntu 24.
Install Node.js and NPM
Node.js and NPM are available in the default Ubuntu repository. Follow the steps below to update your system and install the packages using APT.
-
SSH to your server and update the package information index.
CONSOLE$ sudo apt update
-
Install Node.js.
CONSOLE$ sudo apt install nodejs -y
-
Install NPM.
CONSOLE$ sudo apt install npm -y
-
Ensure you have installed Node.js.
CONSOLE$ node -v
Output:
v18.19.1 (or higher)
-
Ensure you have installed NPM.
CONSOLE$ npm -v
Output:
9.2.0 (or higher)
Create a Hello World!
Application
A Hello World
application is the simplest example of a Node.js application that demonstrates basic functionality, such as creating a server and responding to requests. Follow the steps below to create the application.
-
Make a new
project
directory.CONSOLE$ mkdir project
-
Navigate to the new
project
directory.CONSOLE$ cd project
-
Initialize a Node.js project.
CONSOLE$ npm init -y
-
Create a new
hello-world.js
file using a text editor like Nano.CONSOLE$ nano hello.js
-
Copy the following content and paste it into the
hello-world.js
file.JavaScriptconsole.log("Hello, World!");
-
Save and close the file by pressing Ctrl + X, then Y and Enter.
-
Run the application.
CONSOLE$ node hello.js
-
Ensure you get the following output.
Hello, World!
Conclusion
In this article, you have installed Node.js and NPM on Ubuntu 24.04 The two applications provides you the foundation to build fast and scalable JavaScript-based applications. You've also learned how to verify your installation and created a basic "Hello World!" application, demonstrating the power of Node.js in action.