How to install and configure a Node JS environment

Aktualisiert am 2026-10-23 23:01:23 79 Besuche

In this manual, we will teach you how to easily install a Node JS environment that includes both Node and the 'NPM' package manager, one of the fundamental components of any Node JS environment.

info Please remember that this manual has been written, specifically, for the Ubuntu 18.04 distribution and version. The steps may change for other versions or distributions, although they should be very similar for those distributions based on Debian.

1. Updating the package list

We use the apt-get update command to update the package list and ensure that we always download the latest version of the available packages.

apt-get update

2. Downloading and installing Node js and NPM using the package manager

Next, we must install these two packages: Node JS and npm. Node JS refers to the runtime environment that will allow us to execute code written in Javascript on the server. On the other hand, npm stands for 'Node Packet Manager' or Node package manager. We will use npm to install, manage, and remove Node JS packages and libraries.

apt-get install nodejs npm

3. Verifying the installation

To verify the installation, we will check both the version of nodejs and that of npm. We will do this with the following commands:

nodejs --version
npm --version

If these commands execute without error and show us the installation version, then we will have correctly installed nodejs and npm.

4. Run your first Javascript program on the server with Node JS

Finally, we will create a small 'Hello World' program to demonstrate the functioning of Node JS. First, we will create a text file, for example, with the 'nano' editor.

nano programa.js

Next, copy and paste the code shown below:

file programa.js

console.log('Hello, world!');

Save the file with the CTRL+O key combination and finally, run the program as follows:

node programa.js

success That's it! If you have correctly followed the steps of this tutorial, you will have successfully installed Node JS and NPM, as well as written a small 'Hello World' program to verify its functioning.