Hamsa K
Editor
6 min read | 2 weeks ago

How to Install NodeJs and npm on Ubuntu 20 04

Install nodejs and npm on ubuntu 20.04

Node.js is an open-source, cross-platform, back-end, JavaScript runtime environment that executes JavaScript code outside a web browser.it is also popular as a full-stack and front-end solution. npm is the default package manager for Node.js

This article describes about different ways of installing Node.js and npm on Ubuntu 20.04

First we will install through ubuntu repository.

root@ubuntu20:~# apt update
root@ubuntu20:~# apt install nodejs

check the version with below command.

root@ubuntu20:~# nodejs --version
v10.19.0

using Nodesource repository:

nodejs 14.x (current version)

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

output:

## Run `sudo apt-get install -y nodejs` to install Node.js 14.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
     echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn

once nodesource repository is added to your system,install nodejs using apt.

apt install nodejs

now verify node version

root@ubuntu20:~# node --version
v14.15.0

nodesource package contains both nodejs binary and npm, so no need to install npm. you can check npm version as shown below.

root@ubuntu20:~# npm --version
6.14.8

If you want to install stable version then change setup with setup_12.x

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

using nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash

Then, run following command to source your bash file.

source ~/.profile

Now check all available nodejs versions with below command.

nvm ls-remote

output:

       -------
        ------
        v12.8.0
        v12.8.1
        v12.9.0
        v12.9.1
       v12.10.0
       v12.11.0
       v12.11.1
       v12.12.0
       v12.13.0   (LTS: Erbium)
       v12.13.1   (LTS: Erbium)
       v12.14.0   (LTS: Erbium)
       v12.14.1   (LTS: Erbium)
       v12.15.0   (LTS: Erbium)
       v12.16.0   (LTS: Erbium)
       v12.16.1   (LTS: Erbium)
       v12.16.2   (LTS: Erbium)
       v12.16.3   (LTS: Erbium)
       v12.17.0   (LTS: Erbium)
       v12.18.0   (LTS: Erbium)
       v12.18.1   (LTS: Erbium)
       v12.18.2   (LTS: Erbium)
       v12.18.3   (LTS: Erbium)
       v12.18.4   (LTS: Erbium)
       v12.19.0   (Latest LTS: Erbium)
        v13.0.0
        v13.0.1
        v13.1.0
        v13.2.0
        v13.3.0
        v13.4.0
        v13.5.0
        v13.6.0
        v13.7.0
        v13.8.0
        v13.9.0
       v13.10.0
       v13.10.1
       v13.11.0
       v13.12.0
       v13.13.0
       v13.14.0
        v14.0.0
        v14.1.0
        v14.2.0
        v14.3.0
        v14.4.0
        v14.5.0
        v14.6.0
        v14.7.0
        v14.8.0
        v14.9.0
       v14.10.0
       v14.10.1
       v14.11.0
       v14.12.0
       v14.13.0
       v14.13.1
       v14.14.0
       v14.15.0   (Latest LTS: Fermium)
        v15.0.0
        v15.0.1
        v15.1.0
        v15.2.0

it will display very large list. you can use below command to install a specific version of Node.js

nvm install v(version number)

For example install any version like below.

nvm install v12.16.3

you can list all Node.js versions installed on your system with below command.

nvm ls

output:

root@ubuntu20:~# nvm ls
->     v12.16.3
         system
default -> v12.16.3
node -> stable (-> v12.16.3) (default)
stable -> 12.16 (-> v12.16.3) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/fermium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)

then,install two more versions as shown below

nvm install node
nvm install v13.6.0

now you can list versions.

root@ubuntu20:~# nvm ls
       v12.16.3
->      v13.6.0
        v15.2.0
         system
default -> v12.16.3
node -> stable (-> v15.2.0) (default)
stable -> 15.2 (-> v15.2.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/fermium (-> 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.23.0 (-> N/A)
lts/erbium -> v12.19.0 (-> N/A)
lts/fermium -> v14.15.0 (-> N/A)

Now 13.6.0 is nodejs version in current shell.If you open new shell then default version is v15.2.0. you can switch between installed versions with nvm use command.

nvm use v15.2.0

That's it. you have successfully installed nodejs and npm on ubuntu 20.04



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy