Hamsa K
Editor
7 min read | 3 years 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

Install using ubuntu repository

First we will install nodejs from the standard Ubuntu repository using apt.

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

Also Read -> How to Install MySQL Workbench on Ubuntu 20 04

check the version with below command.

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

Install using Nodesource repository

we can install specific version of  nodejs version using node source 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 -

Also Read -> How to Install Android Studio on Ubuntu 20 04

Install nodejs using NVM

you can install and manage multiple versions of Node.js using node version manager on same system.

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.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
       -------
       -------
       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

Also Read -> How to Install Eclipse IDE 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