Monday, June 29, 2020

NodeJS Installation/Uninstallation on Ubuntu 18.04 and Windows Machine

In the following post, we will try to understand how to install/uninstall nodejs on Ubuntu and Windows system:

What’s Node.js and NPM?

Node.js is a JavaScript-based environment which you can use to create web-servers and networked applications. You can also use it to perform helpful tasks on your computer such as concatenating and minifying JavaScript files and compiling Sass files into CSS.

NPM is a “package manager” that makes installing Node “packages” fast and easy. A package is just a code library that extends the Node by adding useful features. For example, the “request” package simplifies the process of making HTTP requests so you can easily get web resources from other sites.

NPM is installed when you install Node.js


You should have some familiarity with an application that lets you issue command-line instructions. 

For example, the Windows Command Prompt, PowerShell, Cygwin, or the Git shell (which you get when you install Github for Windows).

Ubuntu 18.04 Os

Step 1: Adding the NodeJS PPA to Ubuntu 18.04

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

sudo apt-get install software-properties-common

Sample Output

Sudo Apt Install Software Properties Common

Next, add the NodeJS PPA.

curl -sL | sudo -E bash -

Sample Output

Add Current NodeJS Release

Great! In our next step, we are going to run the command for installing NodeJS.

Step 2: Install NodeJS on Ubuntu

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

sudo apt-get install nodejs

Sample Output

Install NodeJs on Ubuntu 18.04

This command not only installs NodeJS but also NPM (NodeJS Package Manager) and other dependencies as well.

Step 3: Verifying the version of NodeJS and NPM

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

node -v

Sample Output

testing the version of NodeJS in Ubuntu 18.04

For NPM, run

npm -v

Sample Output

Testing the version of NPM

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

vim nodeapp.js

Add the following content

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

node nodeapp.js

Sample Output

Running Node Js Application

This will display the content of the application on port 3000. Ensure the port is allowed on the firewall of your system.

ufw allow 3000/tcp
ufw reload

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


Success Nodejs Has Successfully Been Instaled

Uninstall NodeJS from Ubuntu

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

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:

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

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.

Windows OS

Installation Steps
  1. Download the Windows installer from
  2. Run the installer (the . msi file you downloaded in the previous step.)
  3. Follow the prompts in the installer (Accept the license agreement, click the NEXT button a bunch of times and accept the default installation settings).
  4. Restart your computer.

How to remove Node.js from Windows:

  1. Take a deep breath.

  2. Run npm cache clean --force

  3. Uninstall from Programs & Features with the uninstaller.

  4. Reboot (or you probably can get away with killing all node-related processes from Task Manager).

  5. Look for these folders and remove them (and their contents) if any still exist. Depending on the version you installed, UAC settings, and CPU architecture, these may or may not exist:

    • C:\Program Files (x86)\Nodejs
    • C:\Program Files\Nodejs
    • C:\Users\{User}\AppData\Roaming\npm (or %appdata%\npm)
    • C:\Users\{User}\AppData\Roaming\npm-cache (or %appdata%\npm-cache)
    • C:\Users\{User}\.npmrc (and possibly check for that without the . prefix too)
    • C:\Users\{User}\AppData\Local\Temp\npm-*
  6. Check your %PATH% environment variable to ensure no references to Nodejs or npm exist.

  7. If it's still not uninstalled, type where node at the command prompt and you'll see where it resides -- delete that (and probably the parent directory) too.

  8. Reboot, for good measure.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot