top

How to Install Node.js on Ubuntu

Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. Node.js lets developers use JavaScript to develop wide variety of applications like network applications, command line tools, web api, web applicationsIn this document, we will cover installation procedure of nodejs on Ubuntu 16.04 operating systemPrerequisitesThis guide assumes that you are using Ubuntu16.04. Before you begin, you should have a user account with installation privileges and should have unrestricted access to all mentioned web sites in this document.Audience:This document can be referred by anyone who wants to install latest nodejs on Ubuntu 16.04System requirementsUbuntu 16.044 GB RAM10 GB free space Installation Procedure1.Setup PPATo get you a more recent version of Node.js installed on ubuntu is to add a PPA (personal package archive) maintained by NodeSource. Open terminal and run below commandscd ~ curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.shRun the downloaded script using below command sudo bash nodesource_setup.shThe PPA will be added to your configuration and your local package cache will be updated automatically2.InstallRun sudo apt-get install nodejs -y to install3.Testing InstallationOn terminal run below command to test node node -vYou should see an output like below (Note: Your version may vary depending on your date of installing as nodejs team make an aggressive release but make sure your node version is > v10.0.0)On terminal run below command to test npm npm -vYou should see an output like below (Note: Your version may vary depending on your date of installing as nodejs team make an aggressive release but make sure your npm version is  >5 )Running the first Hello World applicationOpen any text editor and write the following codeconsole.log("Hello World Node!!")Save the file as helloworld.jsOpen command prompt and navigate to the folder where you save helloworld.js and run below commandnode helloworld.jsHow it worksnode command line with file name as an argument will load, read, compile and execute the instructions from the file and execute them. Since we have one line of JS code which prints the text “Hello World Node” to console inside helloworld.js file you see the output as shown in above screenshotUninstall nodejsOn terminal run below command to uninstall nodesudo apt remove nodejs
Rated 4.5/5 based on 20 customer reviews
Normal Mode Dark Mode

How to Install Node.js on Ubuntu

Susan May
Tutorials
08th Feb, 2019
How to Install Node.js on Ubuntu

Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. Node.js lets developers use JavaScript to develop wide variety of applications like network applications, command line tools, web api, web applications

In this document, we will cover installation procedure of nodejs on Ubuntu 16.04 operating system

Prerequisites

This guide assumes that you are using Ubuntu16.04. Before you begin, you should have a user account with installation privileges and should have unrestricted access to all mentioned web sites in this document.

Audience:

This document can be referred by anyone who wants to install latest nodejs on Ubuntu 16.04

System requirements

  • Ubuntu 16.04
  • 4 GB RAM
  • 10 GB free space 

Installation Procedure

1.Setup PPA

  • To get you a more recent version of Node.js installed on ubuntu is to add a PPA (personal package archive) maintained by NodeSource. Open terminal and run below commands
cd ~
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh

  • Run the downloaded script using below command 
sudo bash nodesource_setup.sh

The PPA will be added to your configuration and your local package cache will be updated automatically

2.Install

  • Run sudo apt-get install nodejs -y to install

nodejs -y to install

3.Testing Installation

  • On terminal run below command to test node 
node -v

You should see an output like below (Note: Your version may vary depending on your date of installing as nodejs team make an aggressive release but make sure your node version is > v10.0.0)

  • On terminal run below command to test npm 
npm -v

You should see an output like below (Note: Your version may vary depending on your date of installing as nodejs team make an aggressive release but make sure your npm version is  >5 )

Running the first Hello World application

  • Open any text editor and write the following code
console.log("Hello World Node!!")
  • Save the file as helloworld.js
  • Open command prompt and navigate to the folder where you save helloworld.js and run below command
node helloworld.js

helloworld.js

How it works

node command line with file name as an argument will load, read, compile and execute the instructions from the file and execute them. Since we have one line of JS code which prints the text “Hello World Node” to console inside helloworld.js file you see the output as shown in above screenshot

Uninstall nodejs

  • On terminal run below command to uninstall node
sudo apt remove nodejs

Susan

Susan May

Writer, Developer, Explorer

Susan is a gamer, internet scholar and an entrepreneur, specialising in Big Data, Hadoop, Web Development and many other technologies. She is the author of several articles published on Zeolearn and KnowledgeHut blogs. She has gained a lot of experience by working as a freelancer and is now working as a trainer. As a developer, she has spoken at various international tech conferences around the globe about Big Data.


Website : https://www.zeolearn.com

Leave a Reply

Your email address will not be published. Required fields are marked *

REQUEST A FREE DEMO CLASS

SUBSCRIBE OUR BLOG

Follow Us On

Share on

Useful Links

20% Discount