Tutorials  /  Ubuntu

How to Install and Uninstall NodeJS on Ubuntu 18.04 – Step-by-Step Guide

Ccentron Redaktion · January 2025 ·5 min read ·Ubuntu, Tutorial

NodeJS is a JavaScript framework that allows you to build fast network applications with ease. In this guide, we delve in and see how you can install NodeJS on Ubuntu 18.04.

Step 1: Adding the NodeJS PPA to Ubuntu 18.04

To start off, add the NodeJS PPA to your system using the following commands.

Console
sudo apt-get install software-properties-common

Sample Output

Sudo apt install software properties common

Next, add the NodeJS PPA.

Console
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -

Sample Output

Add current NodeJS releaseGreat! In our next step, we are going to run the command for installing NodeJS.
VM

Matching infrastructure at centron

Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Step 2: Install NodeJS on Ubuntu 18.04

After successfully adding the NodeJS PPA, It’s time now to install NodeJS using the command below.

Console
sudo apt-get install nodejs

Sample Output

Sudo apt get install nodejsThis command not only installs NodeJS but also NPM (NodeJS Package Manager) and other dependencies as well.

Step 3: Verfiying the version of NodeJS and NPM

After successful installation of NodeJS, you can test the version of NodeJS using the simple command below.

Console
node -v

Sample Output

For NPM, run
Console
npm -v

Sample Output

Step 4: Creating a Web Server demonstration

This is an optional step that you can use to test if NodeJS is working as intended. We are going to create a web server that displays the text “Congratulations! node.JS has successfully been installed !”

Let’s create a NodeJS file and call it nodeapp.js

Code
vim nodeapp.js

Add the following content

JavaScript
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Congratulations! node.JS has successfully been installed !\n');
}).listen(3000, "server-ip");
console.log('Server running at https://server-ip:3000/');

Save and exit the text editor

Start the application using the command below

Console
node nodeapp.js

Sample Output

Running node js applicationThis will display the content of the application on port 3000. Ensure the port is allowed on the firewall of your system.
Code
ufw allow 3000/tcp
ufw reload

Now open your browser and browse the server’s address as shown

Code
https://server-ip:3000

Uninstall NodeJS from Ubuntu

If you wish to uninstall NodeJS from your Ubuntu system, run the command below.

Console
sudo apt-get remove nodejs

The command will remove the package but retain the configuration files. To remove both the package and the configuration files run:

Console
sudo apt-get purge nodejs

As a final step, you can run the command below to remove any unused files and free up the disk space

Console
sudo apt-get autoremove

Great! We have successfully installed and tested the installation of NodeJS. We also learned how to uninstall NodeJS from Ubuntu and clean up space.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Ubuntu
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren