Guides and tutorials

Hundreds of tutorials and step by step guides carefully written by our support team.

How to install and configure a Node JS environment

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

info Please note that this manual is 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. Update 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. Download and install nodejs and npm using the package manager

Next, we need to install these two packages: nodejs 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". We will use npm to install, manage and remove Node JS packages and libraries.

apt-get install nodejs npm

3. Verify the installation

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

nodejs --version
npm --version

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

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

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

nano program.js

Then copy and paste the code we show you:

file program.js

console.log("Hello World!");

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

node program.js

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