install-node-js-on-Ubuntu

How to Install Node js in Ubuntu 20.04 Two Methods Explained for Beginners

Node.js is an open source cross-platform JavaScript run-time environment that allows server-side execution of JavaScript code.

In simple words you can run JavaScript code on your machine (server) as a standalone application, and access form any web browser.

When you create a server side application you need Node.js, it is also help to create front-end and full-stack. npm (Node Package Manager) is a package manager for the JavaScript programming language, and default package manager for Node.js.

This tutorial will cover step by step methods “how to install node js in ubuntu 19.04″.

in case you need the latest Node.js and npm versions. If you are using Node.js for development purposes then your best option is to install Node.js using the NVM script.
Although this tutorial is written for Ubuntu the same instructions apply for any Ubuntu-based distribution, including Kubuntu, Linux Mint and Elementary OS.

Important Command Tables

CommandsDescription/Usages
nodejs -vCheck the installed nodejs version
sudo apt-get updateUpdate Ubuntu repository
sudo apt-get install nodejsInstall nodejs on Ubuntu/Debian
sudo apt-get install npmInstall npm on Ubuntu/Debian
sudo apt-get remove nodejsRemove nodejs from Ubuntu/Debian
sudo apt-get purge nodejsRemove Nodejs with its configuration files
sudo apt-get autoremoveRemove unused packages
Useful command to install nodejs on Ubuntu

Check if node js installed already or not

[email protected]:~$nodejs -v

Command 'nodejs' not found, but can be installed with:

sudo apt install nodejs
[email protected]:~$

Prerequisites to install node js in Ubuntu

There is not any specific requirement to install node js in Ubuntu 20.04, but one important thing you should keep in your mind that you have to login with sudo/root user to perform these tasks.

One more thing, Internet should be run on the machine, on which you want to install node.js.

The easiest method to Install node js in Ubuntu 20.04

If you need Node.js only for deploying Node.js applications then the easiest option is to install the Node.js packages using apt/apt-get from the Default Ubuntu repository or from the NodeSource repository.

Ubuntu consists latest and stable package of node.js on its repository. May be you not get latest version from repository but you will get stable version of node.js

You can use following code to install node js in Ubuntu 20.04

$apt-get update
$apt-get install nodejs

[email protected]:~$sudo apt-get install nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libc-ares2 libnode64 nodejs-doc
Suggested packages:
  npm
The following NEW packages will be installed:
  libc-ares2 libnode64 nodejs nodejs-doc
0 upgraded, 4 newly installed, 0 to remove and 32 not upgraded.
Need to get 6,807 kB of archives.
After this operation, 30.7 MB of additional disk space will be used.
Do you want to continue? [Y/n]
[email protected]:~$nodejs -v
v10.19.0
[email protected]:~$

Install npm on Ubuntu 20.04

npm stands for Node Package Manager, allow you to easily install new modules and packages required for Node.js

$sudo apt-get install npm

[email protected]:~$sudo apt-get install npm
[email protected]:~$npm -v
6.14.4
[email protected]:~$

How to install latest version of node.js in Ubuntu 20.04

I installed node.js by using apt-get command, Latest and stable version on ubuntu repository is 10.x. I thought this is latest version, but i was wrong.

When I visited Github of node.js for the latest release, I found latest version is 12.x

Question: How can I install latest version of node.js on Ubuntu, if not installed by using $sudo apt-get install nodejs command on Ubuntu 20.04.

So In this section I will cover install latest version on Ubuntu 20.04

First, curl should be installed on your system. If you don’t have curl installed then use following command to install curl.

$sudo apt-get update
$sudo apt-get install curl

[email protected]:~$sudo apt-get install curl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  curl
0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded.
Need to get 166 kB of archives.
After this operation, 410 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu disco/main amd64 curl amd64 7.64.0-2ubuntu1 [166 kB]
Fetched 166 kB in 2s (79.5 kB/s)
Selecting previously unselected package curl.
(Reading database ... 143463 files and directories currently installed.)
Preparing to unpack .../curl_7.64.0-2ubuntu1_amd64.deb ...
Unpacking curl (7.64.0-2ubuntu1) ...
Setting up curl (7.64.0-2ubuntu1) ...
Processing triggers for man-db (2.8.5-2) ...
[email protected]:~$

Now you can install any version of node.js on Ubuntu system, It may be latest or old version.

Following instruction to install different packages on your system.

Node.js v12.x:

$sudo curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash –
$sudo apt-get install -y nodejs

[email protected]:~$nodejs -v
v12.2.0
[email protected]:~$

Similar you can install any version whatever you want.

Node.js v11.x:

$sudo curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash –
$sudo apt-get install -y nodejs

Node.js v10.x:

$sudo curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –
$sudo apt-get install -y nodejs

Optional: install build tools

To compile and install native addons from npm you may also need to install build tools:

use sudo on Ubuntu or run this as root on debian

$apt-get install -y build-essential

Uninstall node js in Ubuntu

You don’t have use of node.js anymore and don’t want in your Ubuntu system anymore.

Don’t worry, you can uninstall it by following a simple method. The instructions are below.

To remove use following command:

$sudo apt-get remove nodejs

This command will remove your installed package but retain the configuration files. These files will be used by nodejs if you will install again on the same system.

If you want to remove nodejs with its configuration files use the following command

$sudo apt-get purge nodejs

Feeling some light, after uninstalling the package. Do you know “there are some unused packages exist in your system, which was added automatically at the time of installation on node.js.

These packages are called dependencies? if you want to remove those unused packages, run following command.

$sudo apt-get autoremove

How to install nodejs on Ubuntu Video tutorial in Hindi

How to install nodejs on Ubuntu in Hindi

Conclusion

As you can see, there are two methods as described to get up and running node.js on your Ubuntu 20.04. You can find out which method is better for you and go through it.

You can install/update/remove nodejs and npm from your system, whenever you want.

If you like this article please share, If you have any questions, write in the comment box. If you want to contact me through mail id [email protected] use it.

Cheers!

If Appreciate My Work, You should consider: