16 C
Texas

How To Install Node.js on Ubuntu 20.04

Today we are going to learn how to install Node.js on Ubuntu 20.04. Node.js is an open-source cross-platform used for developing web applications, network tools, and other such applications. Node.js comes with two versions. One is long term support and the other is the latest version. Just follow the below steps for the easy and optimal installation of Node.js on Ubuntu 20.04.

Step 1: Update your Ubuntu System

To install any package on our system, first update it to the latest packages. Run the below command in your terminal.

sudo apt -y update

Step 2: Installing Node.js on Ubuntu 20.04

Node.js can be installed on our Ubuntu 20.04 system using different methods. Here I listed the three methods to install Node.js on our Ubuntu system.

  • By Node Source Repository
  • With the help of NVM (I recommend to install using NVM)
  • By Ubuntu Repository
- Advertisement -

You can select your desired option but I recommend to install Node.js using the NVM second method listed above. Here we’ll see all the methods.

Step 3: Install Node.js with Node Source

To install Node.js with the help of Node Source, add the node source repository by firing the below command in your terminal.

Node.js 12 (LTS)

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

Node.js 14 (Current Version)

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

After adding the repository simply hit the below command to install the Node.js. There will be also an additional package installed on your system called NPM. NPM is the Node Package Manager used for the purpose of Java language.

sudo apt -y install nodejs

Verify the version of installed Node.js by running the below command.

node -v

Output:

You’ll see the similar results

sabir@Ubuntu20:~$ node -v
v12.18.0

Also, you can find the NPM version by typing the given command in your terminal.

npm -v

Output:

sabir@Ubuntu20:~$ npm -v
6.14.4

Step 4: Installing Node.js by NVM

NVM stands for Node Version Manager helps us to switch between the different versions of Node.js. So, you can install the desired one with the help of NVM. To install Node.js using NVM, first install the NVM by typing the below command.

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

Now, close the terminal and then open it again to make sure that nvm is loaded.

Then install the Node.js with the help of below command.

Node.js 12 (LTS)

nvm install --lts

Node.js 14

nvm install node

Verify the version by

sabir@Ubuntu20:~$ node -v
v14.4.0
sabir@Ubuntu20:~$ npm -v
6.14.5
sabir@Ubuntu20:~$

Some NVM Commands

You can list the available versions of Node.js with the help of below command.

nvm ls-remote

For installing the specific version just type the name of the version in front of the nvm install command like below.

nvm install 12.18.0

To get list of all installed versions of Node.js on our system hit

nvm ls

Output:

sabir@Ubuntu20:~$ nvm ls
v12.18.0
-> v14.4.0
system
default -> lts/* (-> v12.18.0)
node -> stable (-> v14.4.0) (default)
stable -> 14.4 (-> v14.4.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> v12.18.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.21.0 (-> N/A)
lts/erbium -> v12.18.0

If you want to use different version from installed hit

nvm use 14.4.0

For removing any version hit

nvm uninstall 12.18.0

Step 5: Install Node.js by Ubuntu Repository

As this is available on Ubuntu repository, so its fast and easy to install hit the below command.

sudo apt update
sudo apt install -y nodejs

Verify the version by

node -v

So, this is how you can install Node.js on Ubuntu 20.04 using different methods.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article