Tutorial

How to Install/Uninstall NodeJS on Ubuntu 18.04

Published on August 3, 2022
author

Pankaj

How to Install/Uninstall NodeJS on Ubuntu 18.04

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 How to 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.

sudo apt-get install software-properties-common

Sample Output Sudo Apt Install Software Properties Common Next, add the NodeJS PPA.

curl -sL https://deb.nodesource.com/setup_11.x | 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: Verfiying the version of NodeJS and NPM

After 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

https://server-ip:3000

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.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Pankaj

author

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
February 9, 2020

Thanks, Please change curl -sL https://deb.nodesource.com/setup\_11.x | sudo -E bash - to curl -sL https://deb.nodesource.com/setup\_12.x | sudo -E bash - and }).listen(3000, " server-ip); to }).listen(3000);

- Damien Bushby

    JournalDev
    DigitalOcean Employee
    DigitalOcean Employee badge
    February 7, 2020

    I have run all uninstalling commands but still, it shows node version in ubuntu system

    - S Blckhrt

      Try DigitalOcean for free

      Click below to sign up and get $200 of credit to try our products over 60 days!

      Sign up

      Join the Tech Talk
      Success! Thank you! Please check your email for further details.

      Please complete your information!

      Become a contributor for community

      Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

      DigitalOcean Documentation

      Full documentation for every DigitalOcean product.

      Resources for startups and SMBs

      The Wave has everything you need to know about building a business, from raising funding to marketing your product.

      Get our newsletter

      Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

      New accounts only. By submitting your email you agree to our Privacy Policy

      The developer cloud

      Scale up as you grow — whether you're running one virtual machine or ten thousand.

      Get started for free

      Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

      *This promotional offer applies to new accounts only.