Introduction
Node.js is a JavaScript runtime for server-side programming. Java server helps developers to create scalable backend functionality using JavaScript.
One of the most used common language for web based development.
Pre-requisites
A ubuntu machine with 20.04 flavor
Installation Node.js
Method 1
Ubuntu 20.04 contains node.js version by default , so For many users, using apt
with the default repo will be sufficient.
Using apt will provide you node.js version 10.19, though Java do not mantain this version anymore.
Install Node.js
$ sudo apt update .... $ sudo apt install nodejs .... node -v
Also install npm
it is node package manager
$ sudo apt install npm
Method 2
To install a different version of Node.js, you can use a PPA (personal package archive) maintained by NodeSource. These PPAs have more versions of Node.js available than the official Ubuntu repositories.
Refer to the NodeSource documentation for more information on the available versions.
cd ~ $ sudo curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh
$ sudo nano /tmp/nodesource_setup.sh ... $ sudo bash /tmp/nodesource_setup.sh
The PPA is added to the configuration and automatically local package cache will be updated.
$ sudo apt install nodejs .... node -v
The NodeSource nodejs
package contains both the node
binary and npm
, so you don’t need to install npm
separately.
Method 3
Node Version Manager allows you to install and maintain many different independent versions of Node.js, and their associated Node packages, at the same time.
visit the project’s GitHub page. of Node Version Manager
$ sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh
$ sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
source ~/.bashrc
$ nvm list-remote
$ sudo nvm install v14.10.0
nvm list .... Output -> v14.10.0 v14.21.2 default -> v14.10.0 iojs -> N/A (default) unstable -> N/A (default) node -> stable (-> v14.21.2) (default) stable -> 14.21 (-> v14.21.2) (default) . . .
There are aliases for the various long-term support (or LTS) releases of Node:
Output lts/* -> lts/hydrogen (-> N/A) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.17.0 (-> N/A) lts/dubnium -> v10.24.1 (-> N/A) lts/erbium -> v12.22.12 (-> N/A) lts/fermium -> v14.21.2 lts/gallium -> v16.19.0 (-> N/A) lts/hydrogen -> v18.13.0 (-> N/A)
You can install a release based on these aliases as well. For instance, to install the latest long-term support version, hydrogen
, run the following
sudo nvm install lts/hydrogen ..... Output Downloading and installing node v18.13.0... . . . Now using node v18.13.0 (npm v8.19.3)
You can switch between installed version of NVM use
nvm use v14.10.0 .... Output Now using node v14.10.0 (npm v6.14.8) ``` You can verify that the install was successful using the same technique from the other sections: ```command node -v
Finale
We can use any of the three method defined above get Node.js up and running on Ubuntu 20.04 server.